如何解决地址无效的异常 [英] how resolve Address Invalid exception

查看:1133
本文介绍了如何解决地址无效的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们尝试使用 javax.mail 发送邮件。发送邮件时,我们遇到以下异常:

We tried to send mail using javax.mail. While sending mails we got following exception:

    **sendMail - Message Sending Failed: Invalid Addresses;
    nested exception is: 
javax.mail.SendFailedException: 550 #5.1.0 Address rejected.2013-02-28 13:17:08,236** 

可能是什么问题?

推荐答案

这意味着接收服务器无法识别电子邮件地址的邮箱(@之前的部分)。它可能是拼写错误,它只是一个不存在的名称,或者甚至可能是接收服务器设置为通过回复代码550来拒绝邮件(例如垃圾邮件)。

以下是汇总SMTP回复代码的众多页面之一,并提供了各种相关RFC的链接: http://www.greenend.org.uk/rjk/tech/smtpreplies.html

编辑:我需要更多的空间来回答你的问题,而不是评论允许的。

@RaghuKing,如果你查看Javadoc的 javax.mail.SendFailedException ,你会注意到你可以在这样的异常对象上调用3个方法(在 catch 块内):

It means that the receiving server does not recognise the mailbox (the part before the '@') of the e-mail address. It could be that it was misspelled, that it is simply a non-existing name, or it could even be that the receiving server was set to reject a message (e.g. spam) by replying with code 550.

Here is one of many pages that summarises the SMTP reply codes, and gives links to various relevant RFCs: http://www.greenend.org.uk/rjk/tech/smtpreplies.html.

I need a bit more space to answer your question than the comments allow.

@RaghuKing, if you look at the Javadoc for javax.mail.SendFailedException, you will notice that you can call 3 methods on such an exception object (inside the catch block):


  • getInvalidAddresses( )获取无效且因此未发送到的地址数组,

  • getValidSentAddresses()获取成功发送此消息的地址数组,并

  • getValidUnsentAddresses()获取一个地址数组有效但邮件未发送到该邮件。

  • getInvalidAddresses() to get an array of addresses that are invalid and thus not sent to,
  • getValidSentAddresses() to get an array of addresses to which this message was sent succesfully, and
  • getValidUnsentAddresses() to get an array of addresses that are valid but to which the message was not sent to.

(显然,如果有人向多个收件人发送邮件,有些可能会成功,有些会失败,但会抛出异常如果至少有一次失败,无论成功多少。显然,如果你只发送一个地址,你将只在其中一个数组中有一个地址,它可能不会在 ValidSent中 list。

这些数组将为您提供有关如何处理异常的更多信息,具体取决于地址所在的数组类型。这将是显然取决于你的申请,但这些可能是合理的建议:

These arrays will give you more information how to handle the exception, depending of the type of array an address is in. This will obviously depend on you application, but these might be reasonable suggestions:


  • 无效地址:告诉用户邮件未发送,因为地址错误,列表中的每个无效地址,并提供纠正地址的方法,然后尝试重新发送到正确的地址(或如果用户不提供不同的地址则取消);

  • 有效发送地址:不要重新开始发送;

  • 有效的未发送地址:尝试重新发送到这些地址。由于之前的错误地址,在到达这些地址之前发送可能已停止。

  • Invalid Addresses: tell the user that the message was not sent because the address was wrong, for each invalid address in the list, and provide a way to correct the address, then try to resend to the correct address (or cancel if the user does not provide a different address);
  • Valid Sent Addresses: Don't resend;
  • Valid Unsent Addresses: Try to resend to these addresses. Sending probably stopped before getting to these addresses because of a previous incorrect address.

但最终是你拥有应用常识,也许在你理解它们之前尝试一些你不理解的功能。

But in the end it is you who has to apply common sense, and perhaps experiment a little with the functions you don't understand until you understand them.

这篇关于如何解决地址无效的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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