java exchange发邮件_Java通过Microsoft Exchange Server发送电子邮件

我一直在尝试从我的应用程序(Java Web)发送电子邮件,但它并没有为我工作 . 我正在使用Microsoft Excange Server作为我的主机和端口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发送电子邮件 . 但是当涉及到我的应用程序时,它给了我这个错误 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值