一个JMail发送邮件的问题
public static void main(String[] args)
{
//创建Session对象
Properties p = new Properties();
p.put("mail.transport.protocol","smtp");
p.put("mail.smtp.host","www.163.com");
p.put("mail.smtp.auth","true");
p.put("mail.smtp.port","80");
Session session = Session.getInstance(p,null);
//创建message对象
Message msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress("yangxun122@163.com"));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress("pengli911@163.com"));
msg.setSubject("推荐给你好商品");
msg.setText("kan kanf dsa f dsakfdsa");
Transport transport = session.getTransport("smtp");
transport.connect("www.163.com","yangxun122","123");
transport.send(msg,msg.getAllRecipients());
transport.close();
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
为什么每次都会报一个
javax.mail.MessagingException: Could not connect to SMTP host: www.163.com, port: 80, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:996)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:197)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134) 1 楼 HRoger 2008-03-08 首先mail.stmp.host应该是stmp.163.com,你可以用session.setDebug(true);看看具体的信息,再看这个http://zhidao.baidu.com/question/26773934.html 2 楼 HRoger 2008-03-08 还有是端口是25不是80 3 楼 龙游天下 2008-03-11 谢了,不好意思,端口写错了;还有我知道163的smtp原来不行;后来我改了;它报了一个
javax.mail.MessagingException: Could not connect to SMTP host: www.gmail.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
是不是网速的原因啊