简体   繁体   English

使用Microsoft Exchange Server发送电子邮件

[英]Send email using microsoft exchange server

I am trying to send an email from a microsoft exchange server and i cant seem to make it work. 我正在尝试从Microsoft Exchange服务器发送电子邮件,但似乎无法正常工作。

This is my code: 这是我的代码:

private static void sendEmail(){
  host = "mail.tzr-019.co.il";
  Properties props = System.getProperties();
  props.setProperty("mail.smtps.host", host);
  props.setProperty("mail.smtp.port", "25");
  props.setProperty("mail.smtps.auth", "true");

  Session session = Session.getDefaultInstance(props);

  try{
     MimeMessage message = new MimeMessage(session);
     message.setFrom(new InternetAddress,user));
     message.addRecipient(Message.RecipientType.TO,
                              new InternetAddress(TO));
     message.setSubject("This is the Subject Line!");
     message.setText("This is actual message");
     Transport.send(message);

     System.out.println("Sent message successfully....");
  }catch (Exception mex) {
     mex.printStackTrace();
  }
}

I get the error message: 我收到错误消息:

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
  nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:345)
at javax.mail.Service.connect(Service.java:226)
at javax.mail.Service.connect(Service.java:175)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)

Any ideas? 有任何想法吗?

As I see that you are trying to connect to localhost, I will assume that this is correct and you are the Exchange Server administrator and point to other possibilities. 当我看到您尝试连接到本地主机时,我将假定这是正确的,并且您是Exchange Server管理员,并指出了其他可能性。

Microsoft Exchange server uses by default a proprietary protocol called Exchange Active Sync. 默认情况下,Microsoft Exchange Server使用称为Exchange Active Sync的专有协议。 This is the most common set-up for corporate accounts, and (for example, in my case) other options may not be allowed. 这是公司帐户最常见的设置,并且(例如,在我的情况下)可能不允许使用其他选项。 Each account may have a different privilege on using another protocols as for instance POP3 or IMAP4 and the send counterpart - SMTP. 每个帐户在使用其他协议(例如POP3或IMAP4和发送对方的SMTP)时可能具有不同的特权。

Make sure that the account through you are trying to send the message is supporting the POP3 / IMAP4 synchronization. 确保通过您尝试发送邮件的帐户支持POP3 / IMAP4同步。

See: http://help.outlook.com/en-us/140/cc875899(d=loband).aspx 请参阅: http//help.outlook.com/en-us/140/cc875899(d = loband).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过Microsoft Exchange Server API发送电子邮件(Java) - To send email via microsoft exchange Server api (java) 如何使用 MS Exchange 服务器发送电子邮件 - How to send an email using MS exchange server 我需要从Microsoft Exchange服务器上托管的电子邮件发送电子邮件 - I need to send emails from an email hosted on a Microsoft Exchange server 如何使用Microsoft Exchange发送电子邮件附件? - How to send email attachments with microsoft exchange? 使用MS Exchange Server将邮件发送到Microsoft Outlook中的帐户的连接属性是什么? - What are the connection properties to send mail to an account in Microsoft Outlook using MS Exchange Server? Java使用MS Exchange服务器发送电子邮件 - java sending email using Ms exchange server 如何使用微软交换服务器使用javamail 1.5.1发送邮件? - How to sending mail with javamail 1.5.1 using a microsoft exchange server? ServiceRequestException:使用Java的Microsoft Exchange Server请求失败 - ServiceRequestException: The request failed with Microsoft Exchange Server using Java 使用Java从Microsoft Mail Exchange服务器读取带有附件的邮件 - Read mails with attachments from Microsoft mail Exchange server using Java 使用 MS Exchange Graph API Java SDK 发送带有投票按钮的交换电子邮件 - Send exchange email with voting buttons using MS Exchange Graph API Java SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM