Gaurav Pandey
Gaurav Pandey

Reputation: 2796

Is there a way to know whether an email is successfully relayed with C#?

Is there a way to know whether an email is successfully relayed with C# ?

I am using System.Net.Mail.

Upvotes: 3

Views: 902

Answers (3)

Pranay Rana
Pranay Rana

Reputation: 176896

set MailMessage's DeliveryNotificationOptions propert to
System.Net.Mail.DeliveryNotificationOptions.OnSuccess;

or try :

static void ReadReceipts()
{
//create the mail message
MailMessage mail = new MailMessage();

//set the addresses
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");

//set the content
mail.Subject = "This is an email";
mail.Body = "this is the body content of the email.";

//To request a read receipt, we need add a custom header named 'Disposition-Notification-To'
//in this example, read receipts will go back to '[email protected]'
//it's important to note that read receipts will only be sent by those mail clients that 
//a) support them
//and
//b)have them enabled.
mail.Headers.Add("Disposition-Notification-To", "<[email protected]>");


//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
}

Upvotes: 2

Adam Hopkinson
Adam Hopkinson

Reputation: 28795

Use a service such as Postmark, which allows you to send via smtp or an api and can notify your app of failed messages using a web hook.

Postmark use PowerMTA, an email gateway capable of detecting junk marking, bounces etc. You can go direct through PowerMTA, but Postmark wrap it all up nicely.

Upvotes: 2

Hans Olsson
Hans Olsson

Reputation: 55009

Only way to know if someone has received an email is to ask them to let you know in some way (read reciept or similar).

Which is why all the email confirmation schemes always have that you need to click on a link to confirm that it's your email.

Upvotes: 2

Related Questions