Question: Has anyone ever successfully sent an email to a hotmail account through JavaMail from an SMTP server? If so could you put up the code that worked?

I can send emails to gmail and yahoo accounts using my JavaMail code but I can not send any emails to hotmail accounts. If I use my phone or another email client and use the same SMTP server as my JavaMail code then I can indeed send emails to hotmail accounts. This leads me to believe JavaMail leaves out a flag that hotmail seems to think is important. Using the Apache Commons JavaMail implementation produces the same results.

try{

Email email = new SimpleEmail();

email.setSmtpPort(Integer.parseInt(port));

email.setAuthenticator(new DefaultAuthenticator(from, MyUtilities.getSystemPWD(from)));

email.setDebug(true);

email.setHostName(host);

email.setFrom(from);

email.setSubject(subject);

email.setMsg("test");

email.addTo(to);

email.setStartTLSRequired(true);

email.send();

} catch(Exception ex){

MyLogger.log("MyUtilities.sendEmail: Messaging error",ex);

Logger.getLogger(MyUtilities.class.getName()).log(Level.SEVERE, "MyUtilities.sendEmail: Messaging error", ex);

}

Answer:

There is an accepted answer below but the underlying cause of the problem is that Hotmail requires extra authentication headers (SPF & DKIM) to prove the domain name of your from address is associated with the SMTP server. Using an intermediary SMTP server, like sendgrid, can solve the problem as they will do it for you automatically..at a cost.

You can also attempt to add the needed SPF and DKIM headers yourself.

解决方案

You can try using sendgrid. I just tested it out and if you use legitimate email addresse for the from, it seems to work.

import javax.mail.*;

import javax.mail.internet.*;

import javax.mail.Authenticator;

import javax.mail.PasswordAuthentication;

import java.util.Properties;

public class SimpleMail {

private static final String SMTP_HOST_NAME = "smtp.sendgrid.net";

private static final String SMTP_AUTH_USER = "sendgrid-username";

private static final String SMTP_AUTH_PWD = "sendgrid-password";

public static void main(String[] args) throws Exception{

new SimpleMail().test();

}

public void test() throws Exception{

Properties props = new Properties();

props.put("mail.transport.protocol", "smtp");

props.put("mail.smtp.host", SMTP_HOST_NAME);

props.put("mail.smtp.port", 587);

props.put("mail.smtp.auth", "true");

Authenticator auth = new SMTPAuthenticator();

Session mailSession = Session.getDefaultInstance(props, auth);

// uncomment for debugging infos to stdout

// mailSession.setDebug(true);

Transport transport = mailSession.getTransport();

MimeMessage message = new MimeMessage(mailSession);

Multipart multipart = new MimeMultipart("alternative");

BodyPart part1 = new MimeBodyPart();

part1.setText("Checking to see what box this mail goes in ?");

BodyPart part2 = new MimeBodyPart();

part2.setContent("Checking to see what box this mail goes in ?", "text/html");

multipart.addBodyPart(part1);

multipart.addBodyPart(part2);

message.setContent(multipart);

message.setFrom(new InternetAddress("actual@emailaddress-goeshere.com"));

message.setSubject("Can you see this mail ?");

message.addRecipient(Message.RecipientType.TO,

new InternetAddress("person@tosendto.com"));

transport.connect();

transport.sendMessage(message,

message.getRecipients(Message.RecipientType.TO));

transport.close();

}

private class SMTPAuthenticator extends javax.mail.Authenticator {

public PasswordAuthentication getPasswordAuthentication() {

String username = SMTP_AUTH_USER;

String password = SMTP_AUTH_PWD;

return new PasswordAuthentication(username, password);

}

}

}

java发送hotmail邮件,使用javamail将电子邮件发送到hotmail时遇到问题相关推荐

  1. 一天可以发送多少邮件量,有没发送限制。

    总的来说,根据邮件的发送需求的不同,邮件发送的频率限制要分成三种类型:第一种,验证码:第二种是通知类邮件:第三种是营销类邮件:这三种的限制和要求都不一样,不是在邮件营销,邮件发送这一块做了很多年的朋友 ...

  2. java mail 554_554邮件被拒绝:电子邮件地址未经验证[重复]

    这个问题在这里已有答案: 我正在尝试使用PHPMailer库和Amazon SES服务发送电子邮件 . 我创建了SES帐户并通过添加TXT记录和DKIM设置的CNAME记录来验证我的域名 . 在SES ...

  3. .net 发送html邮件,c#利用system.net发送html格式邮件

    using system; using system.text; using system.net; using system.net.mail; using system.net.mime; nam ...

  4. curl发送html邮件,使用curl命令行发送/发布xml文件

    如果该问题与您的其他Hudson问题有关,请使用它们提供的命令.从命令行使用XML的这种方式: $ curl -X POST -d '...' \ http://user:pass@myhost:my ...

  5. 理光有邮件服务器吗,理光Aficio 3035复印机通过电子邮件发送扫描文件的设定方法及操作步骤...

    [转]http://www.hi-office.cn/ricoh/maintenance/4987.html 理光Aficio 3035复印机通过电子邮件发送扫描文件的设定方法及操作步骤 作者:hio ...

  6. 【转载】如何用Python发送Email邮件?

    文章目录 综述 连接SMTP服务器 登录SMTP服务器 如何获得邮箱授权码 通过SSL登录SMPT服务器 发送\抄送文本邮件 密送文本邮件 发送HTML邮件 参考 综述 用代码发送Email,在很多场 ...

  7. springboot发送QQ邮件(最简单方式)

    前言:使用邮箱注册时发送邮件获取验证码:找回密码时通过邮箱进行验证:或者其他需要发送邮件的场景. 主要针对在springboot中如何发送QQ邮件 1. 准备工作 进入QQ邮箱页面,点击设置,选择账户 ...

  8. 伪造邮件***,看我如何给网易邮箱APP发送垃圾邮件【二】

    Duang~~~好久没更新博客了,源于最近比较忙,感谢博友对我的支持哈~今天继续更新 后面以我在补天漏洞平台提交过的漏洞为入口. 网易邮箱国内用户很多.今天看见他家的app了 ,99.95%垃圾邮件捕 ...

  9. java发送hotmail邮件_利用javamail收取Hotmail的退信

    利用javamail收取Hotmail的退信 (2007-04-05 23:44:19) Hotmail 是我最常用的Email Client.虽然时下hotmail的容量是小了些,速度也常常慢得让人 ...

  10. java 发送附件_Java 基于javaMail的邮件发送(支持附件)

    基于JavaMail的Java邮件发送 Author xiuhong.chen@hand-china.com Desc 简单邮件发送 Date 2017/12/8 项目中需要根据物料资质的状况实时给用 ...

最新文章

  1. redis 管理工具_Redis的跨平台GUI 桌面管理工具
  2. iOS 10应用开发基础教程
  3. ITM_win_agentCPU内存占用较高
  4. 深入分析存储器的位宽及与C的关系
  5. Community Server系列之四:Ajax在CS2.0中的应用1
  6. linux 强行安装软件,Linux下强制不检测依赖安装VNC
  7. Linux下Socket客户端服务器通信
  8. oracle 18c suse,Installing Oracle Database 18c Using RPM Packages
  9. android自动修音,唱吧自动一键修音软件-唱吧自动修音app8.8.6 安卓手机版-东坡下载...
  10. 大数据Spark Continuous Processing
  11. amx-104 r-java_AMX-104 R·贾贾
  12. 955 互联网公司白名单来了!这些公司月薪20k,没有996!福利榜国内大厂只有这家!
  13. html转换成pdf 布局变化,pdf转换成html转换器(Adept PDF to HTML Converter) v3.40免费版
  14. win10桌面上鼠标右键卡顿(一直显示小圆圈)解决办法
  15. 华为OD机试 - 自动曝光(C 语言解题)【独家】
  16. iOS—知乎日报总结
  17. Excel的使用——比对俩列内容的相同与不同,并突出显示
  18. 2022李宏毅机器学习hw1--COVID-19 Cases Prediction
  19. android机开应用速度慢,Android机跑好慢 学会这秘密五招手机瞬间加速!
  20. 移动网络的切换、重选和重定向

热门文章

  1. Spring MVC AOP 初步学习
  2. mysql新建授权账号系列问题
  3. ubuntu命令行相关命令使用心得
  4. 建立域信任关系后,查找位置中看不到另一个域的信息
  5. NewSQL登堂入室 数据库厂商掘金行业大数据
  6. 【转】PCDATA和CDATA的区别究竟是什么呢?
  7. Internet Explorer 8的新特性和自定义部署
  8. HttpWebRequest POST 数据时请求头多了一行Expect: 100-continue,少了数据行
  9. Linux逻辑盘卷管理LVM
  10. Unity多个场景叠加或大场景处理方法小结