Java实现发送邮件

来源:互联网 发布:win7无法打开网络共享 编辑:程序博客网 时间:2024/05/22 04:56

在用Java实现发送邮件时,如果是发送邮箱为qq邮箱通常会失败,方法有两个:

1)mailInfo.setMailServerHost("smtp.exmail.qq.com");

      mailInfo.setMailServerPort("25");

使用smtp.exmail.qq.com服务器。

2)使用SSL协议

props.put("mail.smtp.ssl.enable", "true"); 

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");


使用SSL,端口为465

0 0
原创粉丝点击