c# - 使用 C# SMTP API 时如何从 SES 获得响应

标签 c# amazon-web-services smtp amazon-ses

.Net SmtpClient 的Send 方法返回void。它只抛出两个异常,SmtpExceptionFailureToSendToRecipientsException(或类似的东西)。

使用 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/

相关文章:

c# - 调试时在 Visual Studio 中使用 LINQ

c++ - 在 Linux 上使用 C++ 中的 SMTP 发送邮件

amazon-web-services - AWS block 设备名称与 CentOS SoftLink 不匹配

email - Gerrit 不发送电子邮件

node.js - 使用 nodemailer 通过 Node.js 发送电子邮件不起作用

c# - 有没有一种方法可以让类使用反射访问继承自它的类中的字段?

c# casting 问题

c# - 值类型如何实现引用类型

angular - AWS Cognito : Missing 'get' method for AWS. config.credentials

amazon-web-services - 如何将 DynamoDB 细粒度访问控制与 Cognito 用户池结合使用?