[英]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.