C
chinazxy2008
Unregistered / Unconfirmed
GUEST, unregistred user!
//发邮件
public boolean sendEmail(String to,String subject,String content) {
String host="smtp.163.com";//mail.thinkrev.com
String user="zxyongweb";
String password="zxyongdb";
String from = "zxyongweb@163.com";
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true"
props.put("mail.smtp.host", host);//指定SMTP服务器
props.put("mail.transpost.protocol","smtp"
props.put("mail.smtp.class", "com.sun.mail.smtp.SMTPTransport"
props.put("mail.smtp.auth", "true"//指定是否需要SMTP验证
try
{
Session mailSession = Session.getDefaultInstance(props,new Authen
ticator() {
public PasswordAuthen
tication getPasswordAuthen
tication() {
return new PasswordAuthen
tication("zxyongweb", "zxyongdb"
}
});
mailSession.setDebug(true);//是否在控制台显示debug信息
Message message=new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));//发件人
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));//收件人
message.setSubject(subject);//邮件主题
message.setText(content);//邮件内容
message.saveChanges();
Transport transport = mailSession.getTransport("smtp"
transport.connect(host, user, password);
log.error("开始发送:"
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}catch(Exception e)
{
log.error("发邮件失败:"+e);
System.out.println(e);
return false;
}
log.error("开始成功:"
return true;
}
结果报错
javax.mail.MessagingException: 502 Error: command not implemented
public boolean sendEmail(String to,String subject,String content) {
String host="smtp.163.com";//mail.thinkrev.com
String user="zxyongweb";
String password="zxyongdb";
String from = "zxyongweb@163.com";
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true"
props.put("mail.smtp.host", host);//指定SMTP服务器
props.put("mail.transpost.protocol","smtp"
props.put("mail.smtp.class", "com.sun.mail.smtp.SMTPTransport"
props.put("mail.smtp.auth", "true"//指定是否需要SMTP验证
try
{
Session mailSession = Session.getDefaultInstance(props,new Authen
ticator() {
public PasswordAuthen
tication getPasswordAuthen
tication() {
return new PasswordAuthen
tication("zxyongweb", "zxyongdb"
}
});
mailSession.setDebug(true);//是否在控制台显示debug信息
Message message=new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));//发件人
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));//收件人
message.setSubject(subject);//邮件主题
message.setText(content);//邮件内容
message.saveChanges();
Transport transport = mailSession.getTransport("smtp"
transport.connect(host, user, password);
log.error("开始发送:"
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}catch(Exception e)
{
log.error("发邮件失败:"+e);
System.out.println(e);
return false;
}
log.error("开始成功:"
return true;
}
结果报错
javax.mail.MessagingException: 502 Error: command not implemented