.Net SmtpClient 的Send
方法返回void。它只抛出两个异常,SmtpException
和 FailureToSendToRecipientsException
(或类似的东西)。
使用 SES 时,为了成功发送电子邮件,SES 会发回带有消息 ID 的 200 OK 消息。需要跟踪此消息 ID。
如何使用 C# SMTP api 执行此操作?
编辑:SMTP 协议(protocol)提到了 SMTP 服务器发送的各种响应代码。我正在寻找一个向调用方公开“最终”响应代码的 SMTP 库。我已经知道 SES HTTP API。我暂时不想使用它。
最佳答案
您尝试过 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.SimpleEmail.AmazonSimpleEmailServiceClient
根据 Amazon SES 示例:http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-net.html
关于c# - 使用 C# SMTP API 时如何从 SES 获得响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16662361/