Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get response from SES when using C# SMTP API

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.

like image 779
Amith George Avatar asked May 21 '13 04:05

Amith George


1 Answers

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

like image 183
Jeremy Thompson Avatar answered Oct 06 '22 18:10

Jeremy Thompson