javax.mail.MessagingException: 553 You are not authorized to send mail, authentication is required我在发送mail的时候出现以下错误 ,请各位daxiadaxia大侠指导,非常感谢 !import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.sql.*;public class mailSend {
public static void main(String[] args) throws AddressException,
MessagingException {
try {
//建立邮件会话
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.163.com"); //存储邮件发送服务器的信息
props.put("mail.smtp.auth", "true"); //同时验证
Session s = Session.getInstance(props); //根据属性新建一邮件会话
s.setDebug(true);//由邮件会话新建一个消息对象
MimeMessage message = new MimeMessage(s);//设置邮件
InternetAddress from = new InternetAddress("[email protected]");
message.setFrom(from); //设置发件人
InternetAddress to = new InternetAddress("[email protected]");
message.setRecipient(Message.RecipientType.TO, to); //设置收件人,并设置其接收类型为TO;
message.setSubject("to_title");
message.setText("to_content");
//message.setSentDate(new Date()); //设置发信时间//发送邮件
message.saveChanges(); //存储邮件
Transport transport = s.getTransport("smtp");
transport.connect("smtp.163.com", "[email protected]", "11111111"); //
transport.sendMessage(message, message.getAllRecipients()); //发送邮件,第二个参数是已设好的所有收件人地址
transport.close(); } catch (MessagingException e) {
System.out.println("发送失败!" + e);
}
}
}
import javax.mail.*;
import javax.mail.internet.*;
import java.sql.*;public class mailSend {
public static void main(String[] args) throws AddressException,
MessagingException {
try {
//建立邮件会话
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.163.com"); //存储邮件发送服务器的信息
props.put("mail.smtp.auth", "true"); //同时验证
Session s = Session.getInstance(props); //根据属性新建一邮件会话
s.setDebug(true);//由邮件会话新建一个消息对象
MimeMessage message = new MimeMessage(s);//设置邮件
InternetAddress from = new InternetAddress("[email protected]");
message.setFrom(from); //设置发件人
InternetAddress to = new InternetAddress("[email protected]");
message.setRecipient(Message.RecipientType.TO, to); //设置收件人,并设置其接收类型为TO;
message.setSubject("to_title");
message.setText("to_content");
//message.setSentDate(new Date()); //设置发信时间//发送邮件
message.saveChanges(); //存储邮件
Transport transport = s.getTransport("smtp");
transport.connect("smtp.163.com", "[email protected]", "11111111"); //
transport.sendMessage(message, message.getAllRecipients()); //发送邮件,第二个参数是已设好的所有收件人地址
transport.close(); } catch (MessagingException e) {
System.out.println("发送失败!" + e);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货