程序如下:
package onlyfun.caterpillar;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.SimpleMailMessage;
public class SimpleMailDemo {
public static void main(String[] args) throws Exception {
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
// 设定 Mail Server
senderImpl.setHost( "smtp.163.com ");
// 建立邮件讯息
SimpleMailMessage mailMessage = new SimpleMailMessage();
// 设定收件人、寄件人、主题与内文
mailMessage.setTo( "xxxxxxx@163.com ");
mailMessage.setFrom( "xxxxxxxx1@163.com ");
mailMessage.setSubject( "Test ");
mailMessage.setText( "This is a test!!! ");
// 传送邮件
senderImpl.send(mailMessage);
System.out.println( "邮件传送OK.. ");
}
}
在eclipse执行后,控制台内容如下:
Exception in thread "main " org.springframework.mail.MailSendException; nested exception details (1) are:
Failed message 1:
com.sun.mail.smtp.SMTPSendFailedException: 553 authentication is required,smtp1,wKjRC7C7TAMlDSpGra8jHA==.47118S2 1177160997
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1275)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:388)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:298)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:284)
at onlyfun.caterpillar.SimpleMailDemo.main(SimpleMailDemo.java:22)
希望有做过的指点下!谢谢
------解决方案--------------------
关注