当前位置: 技术问答>java相关
为什么说没有权限发送email?
来源: 互联网 发布时间:2015-07-01
本文导语: package untitled1; import java.util.*; import javax.mail.*; import javax.activation.*; import javax.mail.internet.*; public class MyClass1 { public static void main(String[] args) { try{ Properties props = new Properties(); props.put("mail.smtp.hos...
package untitled1;
import java.util.*;
import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
public class MyClass1 {
public static void main(String[] args) {
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.163.com");
Session s = Session.getDefaultInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("huangbin0791@163.com");
message.setFrom(from);
String toAddress ="Huangbin0791@163.com";
InternetAddress to = new InternetAddress(toAddress);
message.addRecipient(Message.RecipientType.TO, to);
String subject = "hello";
message.setSubject(subject);
String text = "hello javamail";
message.setText(text);
Transport trans;
trans=s.getTransport("smtp");
trans.connect("smtp.163.com","huangbin0791","8975464");
trans.send(message);
}catch (Exception e){
e.printStackTrace();
}
}
}
//----------------------------------------------------------------
//出错信息:
avax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: 553 You are not authorized to send mail as , authentication is required
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at untitled1.MyClass1.main(MyClass1.java:31)
说明: 用户名和密码一定正确!
import java.util.*;
import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
public class MyClass1 {
public static void main(String[] args) {
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.163.com");
Session s = Session.getDefaultInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("huangbin0791@163.com");
message.setFrom(from);
String toAddress ="Huangbin0791@163.com";
InternetAddress to = new InternetAddress(toAddress);
message.addRecipient(Message.RecipientType.TO, to);
String subject = "hello";
message.setSubject(subject);
String text = "hello javamail";
message.setText(text);
Transport trans;
trans=s.getTransport("smtp");
trans.connect("smtp.163.com","huangbin0791","8975464");
trans.send(message);
}catch (Exception e){
e.printStackTrace();
}
}
}
//----------------------------------------------------------------
//出错信息:
avax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: 553 You are not authorized to send mail as , authentication is required
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at untitled1.MyClass1.main(MyClass1.java:31)
说明: 用户名和密码一定正确!
|
是因为你的邮件服务器需要安全验证啦!