java mail 533 异常总结

源代码:

package cn.itcast.javamail;

import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Demo1 {
 public static void main(String[] args)throws Exception{
  Properties props = new Properties();
  props.setProperty("mail.smtp.auth", "true");
  props.setProperty("mail.transport.protocol","smtp" );
  Session session = Session.getInstance(props);
  session.setDebug(true);
  
  Message msg = new MimeMessage(session);
  msg.setText("你好");
  msg.setFrom(new InternetAddress("[email protected]"));

  
  Transport transport = session.getTransport();
  transport.connect("smtp.163.com", 25,"guolimin1118" ,"5304645" );
  transport.sendMessage(msg,new Address[]{new InternetAddress("[email protected]")});
  transport.close();
 }
}

 

异常如下:

RSET
Exception in thread "main" com.sun.mail.smtp.SMTPSendFailedException: 553 You are not authorized to send mail, authentication is required

 at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1668)
 at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1207)
 at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:735)
 at cn.itcast.javamail.Demo1.main(Demo1.java:27)
250 OK
com.sun.mail.smtp.SMTPSendFailedException: 553 You are not authorized to send mail, authentication is required

 at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1668)
 at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1207)
 at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:735)
 at cn.itcast.javamail.Demo1.main(Demo1.java:27)
解决如下:

因为我在guolimin1118账号的服务器上进行了[email protected]得伪装发送

而163是拒绝这样做的

而搜狐和sina却可以这样做

而没有异常

你可能感兴趣的:(异常总结,java,authentication,properties,session,exception,thread)