.Net SmtpClient的Send
方法返回void。它只会抛出两个例外,SmtpException
和FailureToSendToRecipientsException
(或类似的东西)。
使用SES时,为了成功发送电子邮件,SES会发回带有消息ID的200 OK消息。需要跟踪此消息ID。
如何使用C#SMTP api执行此操作?
编辑:SMTP协议提及SMTP服务器发送的各种响应代码。我正在寻找一个SMTP库,向调用者公开“最终”响应代码。我已经知道SES HTTP API了。我暂时不打算使用它。
答案 0 :(得分:3)
您是否尝试过Amazon SES (Simple Email Service) C# Wrapper?
它有一个SendEmail方法,它返回一个带有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;
}
}
我不认为您可以使用System.Net.Mail.SmtpClient
获取您需要使用的MessageId
根据Amazon SES示例Amazon.SimpleEmail.AmazonSimpleEmailServiceClient
:http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-net.html