javaweb 发送邮件 异常解决、 --在线等

l_lcn 2012-04-10 06:12:34
抛出异常:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 Mailbox not found

at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1873)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1120)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at org.nfxy.servlet.SendMail.main(SendMail.java:47)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 Mailbox not found

at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1724)
... 4 more
代码:
public class SendMail extends HttpServlet {
/**
*
*/

private static MailAuthenticator autherticator=null;
public static void main(String[] args) {
for (int i=0;i<5;i++){

String from="546206899@qq.com";
String to="2856493102@qq.com";
String smtpServer="smtp.qq.com";
String subject="Hello ,this is a email Test!!";
String content ="Welcome to you!!";
Properties props = System.getProperties();

props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.auth","true");
autherticator = new MailAuthenticator("546206899@qq.com","xxxxxxxxx");
Session session = Session.getDefaultInstance(props,autherticator);
MimeMessage msg = new MimeMessage(session);
try{
msg.setFrom(new InternetAddress(from));
msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(content);
Transport.send(msg);
System.out.println("成功发送邮件......");
}catch(Exception se){
se.printStackTrace();
}
}
}
}
//现在的大部分的邮件服务器都要求有身份验证,所以需要此类实现验证功能
class MailAuthenticator extends Authenticator{

private String username = null;
private String userpasswd = null;

public MailAuthenticator(){}
public MailAuthenticator(String username,String userpasswd){
this.username = username;
this.userpasswd = userpasswd;
}

public void setUserName(String username){
this.username = username;
}

public void setPassword(String password){
this.userpasswd = password;
}

public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(username,userpasswd);
}
}
...全文
1627 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
singlesteven 2012-04-11
  • 打赏
  • 举报
回复
SMTP配置有误!

很多方面,有可能是你用局域网,有可能是加载的JAR包原因,还有就是QQ邮箱内没开启SMTP服务!
游一游走一走 2012-04-11
  • 打赏
  • 举报
回复
你的代码没有问题,可以正常发送邮件
可能是你QQ邮件的设置问题吧,请尝试换网易或者其他的邮箱试试
cxw3152 2012-04-11
  • 打赏
  • 举报
回复
给你介绍一个比较好用的邮件发送服务 开源的apache-mina下载一个 网上有使用文档 。。 保证一看就懂的。 。里面有发送邮件的代码
昨日凡阳 2012-04-10
  • 打赏
  • 举报
回复
qq邮箱中,smtp等服务是否启用。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧