java发送outlook邮件,如何通过Java从Outlook发送电子邮件?

I am stuck behind a corporate firewall that won't let me send email via conventional means such as Java Mail API or Apache Commons Email, even to other people inside the organization(which is all I want anyways). But my Outlook 2010 obviously can send these emails. I was wondering if there is a way to automate Outlook 2010 via Java code so that Outlook can send the emails ? I know stuff like "mailto" can be used pop-up the default Outlook send dialog with pre-populated info, but I am looking for a way to have the send operation happen behind the scenes. Thanks for any info.

解决方案

You can send emails through outlook with javamail use the configurations described on Outlook's official site.

Here is small demo code

public static void main(String[] args) {

final String username = "your email"; // like yourname@outlook.com

final String password = "*********"; // password here

Properties props = new Properties();

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

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

props.put("mail.smtp.host", "smtp-mail.outlook.com");

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

Session session = Session.getInstance(props,

new javax.mail.Authenticator() {

@Override

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(username, password);

}

});

session.setDebug(true);

try {

Message message = new MimeMessage(session);

message.setFrom(new InternetAddress(username));

message.setRecipients(Message.RecipientType.TO,

InternetAddress.parse("receiver mail")); // like inzi769@gmail.com

message.setSubject("Test");

message.setText("HI you have done sending mail with outlook");

Transport.send(message);

System.out.println("Done");

} catch (MessagingException e) {

throw new RuntimeException(e);

}

}

.

Note: I tested this with Javamail API 1.5.6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值