**************代码
*************错误日志
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.qq.com", port 25, isSSL false
220 smtp.qq.com Esmtp QQ Mail Server
DEBUG SMTP: connected to host "smtp.qq.com", port: 465
EHLO NQSKK7B2UGRHDQX
250-smtp.qq.com
250-PIPELINING
250-SIZE 73400320
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN
250-MAILCOMPRESS
250 8BITMIME
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "73400320"
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "MAILCOMPRESS", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<534814066@qq.com>
503 Error: need EHLO and AUTH first !
com.sun.mail.smtp.SMTPSendFailedException: 503 Error: need EHLO and AUTH first !
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at com.statistic1.pojo.Send1.main(Send1.java:85)
QUIT
221 Bye
com.sun.mail.smtp.SMTPSendFailedException: 503 Error: need EHLO and AUTH first !
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at com.statistic1.pojo.Send1.main(Send1.java:85)
package com.statistic1.pojo;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Send1 {
public Session getSession() {
Properties properties = System.getProperties();
properties.setProperty("mail.imap.host", "imap.exmail.qq.com");
properties.setProperty("mail.stmp.host", "imap.exmail.qq.com");
properties.setProperty("mail.imap.host", "imap.exmail.qq.com");
properties.setProperty("mail.imap.host", "imap.exmail.qq.com");
properties.setProperty("mail.imap.host", "imap.exmail.qq.com");
properties.setProperty("mail.imap.host", "imap.exmail.qq.com");
Session session = Session.getDefaultInstance(properties);
session.setDebug(false);
return session;
}
public static void main(String [] args)
{
// 收件人电子邮箱
String to = "534814066@qq.com";
// 发件人电子邮箱
String from = "534814066@qq.com";
// 指定发送邮件的主机为 localhost
String host = "localhost";
// 获取系统属性
Properties properties = System.getProperties();
// 设置邮件服务器
/*properties.setProperty("mail.imap.host", "imap.exmail.qq.com");
properties.setProperty("mail.imap.port", "993");
properties.setProperty("mail.imap.auth", "true");*/
properties.put("mail.host", "smtp.qq.com");
properties.setProperty("mail.transport.protocol", "smtp");
properties.put("mail.smtp.socketFactory.port", "465");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.port", "465");
properties.put("mail.auth", "true");
//pqckpczfendhcafh
//properties.setProperty("mail.user", "513224066@qq.com");
//properties.setProperty("mail.password", "pqaadckhcafhs");
// 获取默认session对象
Session session = Session.getDefaultInstance(properties);
try {
Transport ts = session.getTransport();
ts.connect("mx1.qq.com", "534814066@qq.com", "pqaadckhcafhs");
session.setDebug(true);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//session.
try{
// 创建默认的 MimeMessage 对象
MimeMessage message = new MimeMessage(session);
// Set From: 头部头字段
message.setFrom(new InternetAddress(from));
// Set To: 头部头字段
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set Subject: 头部头字段
message.setSubject("This is the Subject Line!");
// 设置消息体
message.setText("This is actual message");
// 发送消息
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
}
}