2016-08-30 98 views
0

我被企业防火墙阻挡,不会让我通过传统方式(如Java Mail API或Apache Commons Email)发送电子邮件,甚至是组织内部的其他人(这就是我想要的任何东西)。但我的Outlook 2010显然可以发送这些电子邮件。我想知道是否有办法通过Java代码自动化Outlook 2010,以便Outlook可以发送电子邮件?我知道像“mailto”这样的东西可以用于预先填充的信息弹出默认的Outlook发送对话框,但我正在寻找一种方法让发送操作在幕后进行。感谢您的任何信息。如何通过Java从Outlook发送电子邮件?

回答

1
Process p = Runtime.getRuntime().exec("cmd /C start outlook "); 
+2

这不会启动Outlook GUI吗?这似乎与OP正在寻找的是相反的。对不起,我无法贡献更多。 –

0

我不认为有什么办法可以使用Outlook来做你想做的事。

推测你的邮件服务器也在企业防火墙之后。如果您为客户端使用Outlook,则可能是使用Exchange作为服务器。 Exchange可以配置为支持用于发送邮件的标准SMTP协议,这将允许使用JavaMail。如果您无法将Exchange服务器配置为支持SMTP,则仍可以使用Exchange Web Services。如果这不起作用,您可能需要使用支持Microsoft专有邮件协议的JavaMail Third Party Products之一。

3

您可以通过Outlook发送电子邮件与javamail使用上Outlook's official site.

所述的配置这里是小的演示代码

public static void main(String[] args) { 
    final String username = "your email"; // like [email protected] 
    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 [email protected] 
     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); 
    } 
} 


注:我测试了这个与Javamail API 1.5.6

+0

我认为OP并不意味着使用微软的电子邮件服务器,而是微软的电子邮件客户端程序。令人困惑的是,两者都被命名为“展望”。 – JosefScript

相关问题