81,092
社区成员
发帖
与我相关
我的任务
分享
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 {
/**
* @param args
*/
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("111@sohu.com"));
Transport transport=session.getTransport();
transport.connect("smtp.163.com" , 25, "ange****","******");
transport.sendMessage(msg,new Address[]{new InternetAddress("l****@163.com") });
transport.close();
}
}
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.163.com", port 25, isSSL false
220 163.com Anti-spam GT for Coremail System (163com[20081010])
DEBUG SMTP: connected to host "smtp.163.com", port: 25
EHLO MICROSOF-LI
250-mail
250-PIPELINING
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg "PLAIN"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 dXNlcm5hbWU6
YW5nZWxjbTUx
334 UGFzc3dvcmQ6
MTk4NzEwMjM=
235 Authentication successful
DEBUG SMTP: use8bit false
MAIL FROM:<111@sohu.com>
553 You are not authorized to send mail, authentication is required
DEBUG SMTP: got response code 553, with response: 553 You are not authorized to send mail, authentication is required
RSET
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:33)
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:33)