c#发送邮件 邮箱不可用_.net c#使邮箱不可用.无效收件人过多错误

Our application sends out emails using the

new SmtpClient(smtpServer).Send(message);

We are making sure that the smtpServer is valid, the message has To and From addresses, a subject and a body. If any of these are missing, we would log an exception before even attempting to send a message.

But the application frequently fails with the below exception.

Email Fail: System.Net.Mail.SmtpException: Mailbox unavailable. The server response was: Too many invalid recipients.

Now, please note that the email send functionality is not failing always. For the same "To" address, it fails, may be about half the times. So, if the application tries sending out emails 100 times, we are getting some 40+ failures with the same message.

I have already validated that the To address and the From address exists. We are seeing this issue since last month when we shifted from Outlook to Gmail.

Here is the code.

if (fromAddress.Length == 0)

fromAddress = Resources.FromAddress;

if (toAddress.Length == 0) return "To Address is Required.";

if (smtpServer.Length == 0)

smtpServer = Resources.SMTPServer;

if (string.IsNullOrEmpty(smtpServer))

return "SMTP sever not specified";

MailMessage mailMessage = new MailMessage();

//set the addresses

mailMessage.From = new MailAddress(fromAddress);

string[] toAdds = toAddress.Split(';');

short i = 0;

foreach (string address in toAdds)

{

if(i==0) mailMessage.To.Add(address); else mailMessage.CC.Add(address);

i++;

}

if (!string.IsNullOrEmpty(bcc))

{

string[] bccAddresses = bcc.Split(';');

foreach (string address in bccAddresses)

{

mailMessage.Bcc.Add(address);

}

}

if (!string.IsNullOrEmpty(cc))

{

string[] ccAddresses = cc.Split(';');

foreach (string address in ccAddresses)

{

mailMessage.CC.Add(address);

}

}

if (subject.Length > 0)

mailMessage.Subject = subject;

mailMessage.Body = sBody;

mailMessage.IsBodyHtml = true;

SmtpClient emailClient = new SmtpClient(smtpServer);

emailClient.Send(mailMessage);

Any directions?

Talk1:

Feroz this can happen for a number of reasons.. if you have individual emails and one of them has an invalid hostname in their email address, or if you have not parsed the recipients list properly.. perhaps you have 2 email address colliding for example tomthumb@aol.commarrK@gmail.com and there is no proper separator.. the best thing I would suggest is to set break points process the large list and see which email(s) it fails on and inspect the value.. it's probably something so simple..

Talk2:

also without exposing the actual recipients email addresses to us could you give an exact example of the emails masking them or changing them ...

Talk3:

We have just one email address in "To" and one in "CC". Something like "axxxxs@txxxxk.com" in To and "axxxxk@rxxxxd.com" in CC and the From address is like Axxxxs@rxxxxd.com

Talk4:

This has become a difficult one to crack since all the emails are being sent to the same "To", same "CC" and from the same "From" addresses and some of them are failing. The angle of Outlook Vs Gmail is also interesting since the complaints started coming in at around the same time when the company shifted from Outlook to Gmail.

Talk5:

show the code of how you are sending multiple emails and how you are assigning it's delimited separator.. for example are you using , or ; for the email separator.. and also are you trimming or getting the substring position of the last email which you would not have to use the ending separator so it should looks something like this in your inspector "axxxxs@txxxxk.com;""axxxxk@rxxxxd.com" in the CC portion

Solutions1

If the same email with the same sender and recipients is sometimes accepted, sometimes rejected by the SMTP server, it may be the result of a server antispam policy. For example :

Directory Harvest Attack Prevention (DHAP) : which causes a "550 Too many invalid recipients" error when exceeding a number of RCPT TO commands over a given period of time.

Quotas : a limit on the number of mails that a mailbox/IP can send per minute/second to prevent spamming.

You can validate if the SMTP server settings are the cause of your problem by (temporarily) :

whitelisting the IP address of your SMTP client

disabling any quota/antispam Policy applied to your sender's mailbox

If that doesn't solve your problem, then use a tool like WireShark to record the SMTP dialog and check exactly what email addresses are sent in the RCPT TO command, and in which cases the SMTP Server rejects them. Then, post it here.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值