为什么 sendTo 的电子邮件址址用自己本机的地址就行也可以发送到本机,但如果用一般的电子邮件地址如:
xxx@xxx.com ,就出现如下错误:
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.util.*;
public class SendMail {
private String sendTo = "my.goto.net";//本机的,测试其他的是用
xxx@xxx.com
private String sendFrom = "
my@my.com";
private String subject = "Hello,This is a email";
public SendMail() {
}
public void send(){
try{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
sendMailSession = Session.getInstance(props, null);
props.put("mail.smtp.host", "my.goto.net");
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(this.sendFrom));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(this.sendTo));
newMessage.setSubject(this.subject);
newMessage.setSentDate(new Date());
newMessage.setText("this is content,succeed.");
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
}catch(AddressException e){
System.out.println("-----------address exception-----------");
e.printStackTrace();
}catch(MessagingException e){
System.out.println("-----------message exception-----------");
e.printStackTrace();
}
}
public static void main(String args[]){
SendMail s = new SendMail();
System.out.println("----------------- start ------------------");
s.send();
System.out.println("----------------- succeed ------------------");
}
}
为什么 sendTo 的电子邮件址址用自己本机的地址就行也可以发送到本机,但如果用一般的电子邮件地址如:
xxx@xxx.com ,就出现如下错误:
----------------- start ------------------
-----------message exception-----------
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550 5.7.1 Unable to relay for
xxx@xxx.com
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at mail.SendMail.send(SendMail.java:41)----------------- succeed ------------------
at mail.SendMail.main(SendMail.java:54)
是怎么回事?