关于Javamail的问题~~~为什么我尝试了很多次都是抛出异常,用什么邮箱都不行!!!求大神指教
publicclassMain{publicstaticvoidmain(String[]args){//创建Mail_SendProper类的对象,用于获取邮件的基本消...
public class Main {
public static void main(String[] args) {
//创建Mail_SendProper类的对象,用于获取邮件的基本消息
Mail_SendProper mailSender = new Mail_SendProper();
mailSender.setHost("smtp.qq.com");
mailSender.setPort("25");
mailSender.setIsvalidate(true);
mailSender.setUserName("1013018970@qq.com");
mailSender.setPassWord(""); //这里不方便写出来
mailSender.setSendAddress("1013018970@qq.com");
mailSender.setReceiveAddress("lhq1013018970@163.com");
mailSender.setSubject("我的邮件测试!!!");
mailSender.setContent("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
//Send_Mail.Mail_Text(mailSender); //以文本格式发送邮件
Send_Mail ss=new Send_Mail();
ss.Mail_Text(mailSender);
}
}
抛出的是这个异常~~~javax.mail.AuthenticationFailedException异常!!
javax.mail.AuthenticationFailedException异常
javax.mail.AuthenticationFailedException异常
javax.mail.AuthenticationFailedException异常
javax.mail.AuthenticationFailedException异常
javax.mail.AuthenticationFailedException异常
javax.mail.AuthenticationFailedException异常 展开
public static void main(String[] args) {
//创建Mail_SendProper类的对象,用于获取邮件的基本消息
Mail_SendProper mailSender = new Mail_SendProper();
mailSender.setHost("smtp.qq.com");
mailSender.setPort("25");
mailSender.setIsvalidate(true);
mailSender.setUserName("1013018970@qq.com");
mailSender.setPassWord(""); //这里不方便写出来
mailSender.setSendAddress("1013018970@qq.com");
mailSender.setReceiveAddress("lhq1013018970@163.com");
mailSender.setSubject("我的邮件测试!!!");
mailSender.setContent("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
//Send_Mail.Mail_Text(mailSender); //以文本格式发送邮件
Send_Mail ss=new Send_Mail();
ss.Mail_Text(mailSender);
}
}
抛出的是这个异常~~~javax.mail.AuthenticationFailedException异常!!
javax.mail.AuthenticationFailedException异常
javax.mail.AuthenticationFailedException异常
javax.mail.AuthenticationFailedException异常
javax.mail.AuthenticationFailedException异常
javax.mail.AuthenticationFailedException异常
javax.mail.AuthenticationFailedException异常 展开
2个回答
展开全部
验证错误呗。三种可能性1.用户名密码不对 2.我记得java mail有个选项要设置 mail.smtp.auth为true才行的。3.登录qq邮箱,开通smtp服务
-------不知道你有没有用过spring的 mailsender, 封装了javamail,简化使用方法。spring javamail举例:
xml:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="protocol" value="smtp"/>
<property name="host" value="smtp.qq.com"/>
<property name="port" value="25" />
<property name="username" value="xxx"/>
<property name="password" value="xxx"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
</bean>
@Autowired
private JavaMailSender mailSender;
@Override
public void sendCommonMail(String toMailAddr, String subject, String message) {
try{
MimeMessage mime = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mime, true, "utf-8");
helper.setFrom(ResourceUtil.getConfigByName("mail_from"));//发件人
helper.setTo(toMailAddr);//收件人
helper.setSubject(subject);//邮件主题
helper.setText(message, false);
mailSender.send(mime);
}catch(Exception e){
org.jeecgframework.core.util.LogUtil.error("email send error", e);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询