如何使用MS Exchange Server发送电子邮件 [英] How to send an email using MS exchange server

查看:150
本文介绍了如何使用MS Exchange Server发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用公司的邮件服务器发送电子邮件.但是我遇到了以下异常

I am trying to sent an email using my company's mail server. But I am getting the following exception

Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Client was not authenticated
    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)

这是我的示例代码,

Properties props = System.getProperties();

// Setup mail server
props.put("mail.smtp.host", "example.server.com");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", "25");
// Get session
//Session session = Session.getDefaultInstance(props, null);
Session session = Session.getDefaultInstance(props,
    new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("username", "password");
        }
    });

// Define message
MimeMessage message = new MimeMessage(session);

// Set the from address
message.setFrom(new InternetAddress(from));

// Set the to address
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

// Set the subject
message.setSubject("Hello JavaMail");

// Set the content
message.setText("Welcome to JavaMail");

// Send message
Transport.send(message);

哪段代码是错误的? 作为用户名和密码,我正在使用公司的电子邮件地址和密码.

What piece of code is wrong? As as username and password , I am using my company's email address and password.

推荐答案

5.7.1可能是由于交换而不是您的代码引起的.您可能只需要在服务器上启用中继.无论是匿名用户还是来自某个IP地址的用户.我不是Exchange方面的专家,但我之前已经做过这项工作.这是我测试过的最后一个可行的解决方案:

The 5.7.1 is probably caused by exchange and not your code. You may just need to enable relaying on the server. Either for anonymous users or from a certain IP address. I'm not an expert on Exchange but I have got this working before. Here is the last solution I tested that works:

如果在通过用户身份验证后尝试在Exchange Server上通过SMTP发送电子邮件时遇到5.7.1错误.

If a 5.7.1 error is encountered when trying to send an email via SMTP on an exchange server when the user has been authenticated..

作为参考,您刚遇到的问题是由Exchange 2007服务器上的设置引起的–通常在2003服务器上不会出现问题

For ref the issue you just had was caused by a setting on the Exchange 2007 server – this would not normally be a problem on 2003 server

已通过以下操作完成...

Fixed by doing below...

您可以通过GUI设置此身份验证设置

You can set this authentication setting via the GUI

  • 在服务器配置/集线器传输/默认< ServerName>
  • 右键单击,属性,权限组
  • 选中匿名用户",然后单击确定"

显然,匿名用户不是很安全,但是您可以看到这是否可以解决问题.

Obviously anon users is not too secure but you could see if this solves the problem.

这篇关于如何使用MS Exchange Server发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆