当前位置: 技术问答>java相关
关于javamail的问题,清高首解答
来源: 互联网 发布时间:2015-01-24
本文导语: package mailsender; import java.util.Properties; import javax.mail.*; import javax.activation.*; import javax.mail.internet.*; public class mailsender { public static void main(String[] args) throws Exception { String host="127.0.0.1"; Stri...
package mailsender;
import java.util.Properties;
import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
public class mailsender {
public static void main(String[] args) throws Exception {
String host="127.0.0.1";
String from="huzengli@elong.com";
String to="huzengli@21cn.com";
Properties props=System.getProperties();
props.put("mail.smtp.host",host);
Session session=Session.getInstance(props,null);
MimeMessage message=new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Hello javamail");
message.setText("welcome to javamail");
Transport transport=session.getTransport("smtp");
transport.send(message);
}
}
上面这段代码编译通过了,但是在执行时,系统抛出异常:说目的地址有错误即 "huzengli@21cn.com"有错,请问是什么原因。谢谢
import java.util.Properties;
import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
public class mailsender {
public static void main(String[] args) throws Exception {
String host="127.0.0.1";
String from="huzengli@elong.com";
String to="huzengli@21cn.com";
Properties props=System.getProperties();
props.put("mail.smtp.host",host);
Session session=Session.getInstance(props,null);
MimeMessage message=new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Hello javamail");
message.setText("welcome to javamail");
Transport transport=session.getTransport("smtp");
transport.send(message);
}
}
上面这段代码编译通过了,但是在执行时,系统抛出异常:说目的地址有错误即 "huzengli@21cn.com"有错,请问是什么原因。谢谢
|
你本地的服务器有问题