1

References to this link, I understand how to send email to many recipients my question is if one of them fail this mean Send(Msg) will throw error for all ? or just for specific recipient appreciate any help thanks

CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
amir
  • 23
  • 5
  • 1
    What do you mean by fail? – CodeNotFound Apr 26 '18 at 15:19
  • throw error @CodeNotFound – amir Apr 26 '18 at 15:21
  • You can have only two kind of errors I think : - First when the SMTP server is not reachable so the fail concerns all recipient addresses. - Second when one of the recipient email is invalid so use the same solution in the link you posted in your question. – CodeNotFound Apr 26 '18 at 15:23
  • fail like email not exist or received the message @CodeNotFound – amir Apr 26 '18 at 15:23
  • 1
    You can't do that in your application. When the recipient is valid format but doesn't exist, the recipient SMTP server just send an email to the expeditor. So your application will not know about that at least you make a process that check for specific email received from recipients. – CodeNotFound Apr 26 '18 at 15:25
  • in case one of the recipient email is invalid this mean Send(Msg) will throw error? I intend to put send email in retry action, so this means the message will sent again to the other recipient this is my concern @CodeNotFound – amir Apr 26 '18 at 15:28
  • Yes is the answer for your question. For that you need to call Send(Msg) for each recipient. – CodeNotFound Apr 26 '18 at 15:32
  • I am so grateful for your answer, the last thing is if all recipients are valid as email format but one of them, not real or not receive the message for some reason lets say not enough space, this means Send(Msg) will throw error ? @CodeNotFound and I also need to call Send(Msg) for each recipient – amir Apr 26 '18 at 15:37
  • No :). Send method just mean => I reach the SMTP server and just give ti the mail to deal with it. Everything else that happen after that your application are not notified about it. – CodeNotFound Apr 26 '18 at 15:39
  • 1
    Well, you could have checked the [documentation for SmtpClient.Send](https://msdn.microsoft.com/en-us/library/swas0fwc(v=vs.110).aspx) - _"When sending e-mail using Send to multiple recipients and the SMTP server accepts some recipients as valid and rejects others, Send sends e-mail to the accepted recipients and then a SmtpFailedRecipientsException is thrown. The exception will contain a listing of the recipients that were rejected."_ – stuartd Apr 26 '18 at 15:41
  • my SMTP (send from smtp) true @CodeNotFound ? – amir Apr 26 '18 at 15:42
  • @CodeNotFound kindly write your answer so I can mark as the true answer, thanks – amir Apr 26 '18 at 15:43
  • @stuartd thanks it's really help – amir Apr 26 '18 at 16:53

1 Answers1

5

Assuming you are using System.Net.Mail.SmtpClient.Send(MailMessage), the documentation shows that it can throw a "SmtpFailedRecipientsException" exception when the message could not be delivered to one or more of the recipients in MailMessage.To, MailMessage.CC, or MailMessage.Bcc.

The SmtpFailedRecipientsException exception has an InnerExceptions property.

Gets one or more SmtpFailedRecipientExceptions that indicate the e-mail recipients with SMTP delivery errors.

https://msdn.microsoft.com/en-us/library/swas0fwc(v=vs.110).aspx

Note: Depending on the issue, the SMTP server may accept the message and fail to deliver it to the recipient further along in the process.

Wiz
  • 406
  • 3
  • 7
  • if if all recipients are valid as email format but one of them not real or not receive the message for some reason lets say not enough space this means SmtpFailedRecipientsException will throw ? – amir Apr 26 '18 at 16:01
  • 1
    @amir no, in that situation there is no way to tell from the sending side that it failed. The only way to tell would be check the reply address you set to see if you got a email saying the send failed. Think of it like a real letter you send to a new town, you drop off your letter to the local post office, if something went wrong on the way to the local post office you would know right away. But if the post office accepted your letter but the address turned out to be a empty lot, how do you find out? You find out via the post office in the other town using the reply address to send it back. – Scott Chamberlain Apr 26 '18 at 16:06
  • which you would need to go out later and check your mailbox to see if you received the returned letter. If something else goes wrong, for example there was a fire at the new town's post office and your letter was burnt up destroying the return address label, there would be no way for the other post office to know where to send a note saying that the letter was not delivered, so just because the letter was not returned to you does not mean it got there successfully. SMTP works exactly the same, the only way you know if the email did not get there is if the server sent a reply email saying so. – Scott Chamberlain Apr 26 '18 at 16:13
  • thanks @Scott Chamberlain , so if I am sure the email format 100% true and my send(msg) in retry method no exception will be throw, my concern just not to resend to the other recipients again and the retry stop when no exception throw – amir Apr 26 '18 at 16:28
  • @Scott Chamberlain so if one of them not real or not receive the message for some reason lets say not enough space, no exception will throw ? – amir Apr 26 '18 at 16:51
  • @amir Yes. Just like if you dropped a real letter at the post office, once you drop it off you don't know what happens after. – Scott Chamberlain Apr 26 '18 at 17:09
  • Scott Chamberlain , Wiz , CodeNotFound , stuartd you all help me how can I mark you all as write answer :) because really every one help me in some point to understand the complete picture – amir Apr 26 '18 at 17:34
  • @Scott Chamberlain – amir Apr 26 '18 at 17:34
  • @Wiz ,,,,,,,,,,, – amir Apr 26 '18 at 17:34
  • @CodeNotFound , – amir Apr 26 '18 at 17:35
  • @stuartd ,,,,,,, – amir Apr 26 '18 at 17:35
  • @amir no problem, glad to help. – stuartd Apr 26 '18 at 17:36