Below code is workin fine . However I need get Failure or Success Notification to Specific address ([email protected]). But I'm receiving Delivery Notification mail to FromMail address([email protected]). Can you please help me to resolve this problem?
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("[email protected]", "BALA");
MailAddress adminAddress = new MailAddress("[email protected]");
smtpClient.Host = "Mail Server Name";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = true;
message.From = fromAddress;
message.To.Add(_sendTo); //Recipent email
message.Subject = _subject;
message.Body = _details;
message.IsBodyHtml = true;
message.Headers.Add("Disposition-Notification-To", "[email protected]");
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
message.ReplyTo = adminAddress;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Send(message);
A Delivery Status Notification (DSN), or simply a bounce, is an automated electronic mail message from a mail system informing the sender of another message about a delivery problem. The original message is said to have bounced. Errors can occur at multiple places in mail delivery.
What happens if a message sent via SMTP cannot be delivered? The server generates a non-delivery report (NDR) with an appropriate error code.
What Is Email Delivery? Standard Email Delivery is when an email is sent to a receiving mail server over SMTP. The mail server then chooses whether or not it would like to accept the message. This happens before the message is placed in the inbox or spam folder.
When you get mail from a "MAILER-DAEMON" or a "Mail Delivery Subsystem" with a subject like "Failed Delivery" or similar, it means that an email you sent was undeliverable and has been "bounced" back to you. These messages are produced automatically and usually include a reason for the delivery failure.
The short answer is what you are asking cannot be done in the direct manner in which you are assuming.
This will only work in certain conditions. The easiest to describe would be if the SMTP server you are using to send the message, is the same server that hosts the domain of the recipient email messages (the server you refer to when setting your .HOST property of smtpClient). So, if you were only sending to recipients on your local SMTP mail server, then this might work pretty reliably. But that depends on the specific SMTP server software being used and potentially also on how it is configured.
To explain why this is, you must realize that only the last SMTP mail server receiving the message that actually hosts the desired email addresses, will be able to authoritatively answer the question, is this a valid email address. If the message has to pass through any other email servers on the way to getting at this final authoritative server, the message has to be handed off sequentially from one server to the next server in the chain until it reaches that final authoritative server. This means that there is not a guaranteed method for authenticating a specific address. Couple this with the fact that some domains are configured to act as a black hole and swallow illegitimately addressed mail, and you can see that there are many reasons why you cannot rely on that methodology.
So, many messages to external domains are going to have to hit at least one separate SMTP server and depending on how that server answers or forwards the mail, it will determine the results for any specific receiving domain. In fact, monitoring the FROM address for bounced messages is not foolproof either as my previous comment about some hosts putting some messages into a black hole if they do not appear to be valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With