Java通过Microsoft Exchange Server发送电子邮件

Java通过Microsoft Exchange Server发送电子邮件,java,email,exchange-server,Java,Email,Exchange Server,我一直在尝试从我的应用程序Java web发送电子邮件,但它对我不起作用。我使用Microsoft Exchange服务器作为主机和端口25,但我一直得到以下结果: Caused by: java.lang.RuntimeException: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Client was not authenticated at com.mimacs.scheduler.SendEmailImpl.execute(

我一直在尝试从我的应用程序Java web发送电子邮件,但它对我不起作用。我使用Microsoft Exchange服务器作为主机和端口25,但我一直得到以下结果:

Caused by: java.lang.RuntimeException: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Client was not authenticated
at com.mimacs.scheduler.SendEmailImpl.execute(SendEmailImpl.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)
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 com.mimacs.scheduler.SendEmailImpl.execute(SendEmailImpl.java:72)
... 9 more
我的代码如下:

    public void sendEmail() {


    boolean debug = true;

    Properties props = new Properties();
    props.put("mail.smtp.host", "myHost");
    props.put("mail.smtp.auth", "true");
    props.put("mail.debug", debug);
    props.put("mail.smtp.port", 25);
    props.put("mail.smtp.starttls.enable", debug);
    props.put("mail.transport.protocol", "smtp");

    Session session = Session.getDefaultInstance(props,
            new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
   return new PasswordAuthentication("myusername@example.com",  "mypassword");});

    session.setDebug(debug);

    try {
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("myusername@example.com"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("someone@example.com"));
        message.setSubject("Testing Subject");
        message.setText("Sending email through Microsoft Exchange Server");
       Transport.send(message);
    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }

请你帮我指出哪里出了问题。我可以使用相同的电子邮件地址和登录凭据从outlook发送电子邮件。但在我的应用程序中,它给了我这个错误。

。。请检查一下这个。。您需要做的是删除props.putmail.smtp.auth,true;感谢ArunM,做出了改变,现在一切正常。再次感谢你。