The .Net SmtpClient's Send
method returns void. It only throws two exceptions, SmtpException
and a FailureToSendToRecipientsException
(or something like that).
When using SES, for successful email delivery SES sends back a 200 OK message with the message id. This message id needs to be tracked.
How do I do this using the C# SMTP api?
Edit: The SMTP protocol mentions various response codes sent by the SMTP server. I am looking for a SMTP library that exposes the "final" response code to the caller. I am already aware of the SES HTTP API. I am not looking to use that for the moment.
Have you tried the Amazon SES (Simple Email Service) C# Wrapper?
It has an SendEmail method that returns a Class with the MessageId:
public AmazonSentEmailResult SendEmail(string toEmail, string senderEmailAddress, string replyToEmailAddress, string subject, string body)
{
List<string> toAddressList = new List<string>();
toAddressList.Add(toEmail);
return SendEmail(this.AWSAccessKey, this.AWSSecretKey, toAddressList, new List<string>(), new List<string>(), senderEmailAddress, replyToEmailAddress, subject, body);
}
public class AmazonSentEmailResult
{
public Exception ErrorException { get; set; }
public string MessageId { get; set; }
public bool HasError { get; set; }
public AmazonSentEmailResult()
{
this.HasError = false;
this.ErrorException = null;
this.MessageId = string.Empty;
}
}
I dont think you can get the MessageId with System.Net.Mail.SmtpClient
you will need to use
Amazon.SimpleEmail.AmazonSimpleEmailServiceClient
as per the Amazon SES sample: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-net.html
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