使用Amazon SES以C#格式发送带有附件的电子邮件

使用Amazon SES以C#格式发送带有附件的电子邮件,c#,amazon-ses,C#,Amazon Ses,我正在使用亚马逊SES发送电子邮件。如何使用Amazon SES以C#格式发送带有附件的电子邮件 代码: AmazonSES没有什么特别之处,只需指定smtp服务器并发送即可 public static void SendWithSMTP(string name, string pass, string host, int port) { using (var client = new System.Net.Mail.SmtpClient(host, port)) {

我正在使用亚马逊SES发送电子邮件。如何使用Amazon SES以C#格式发送带有附件的电子邮件

代码:


AmazonSES没有什么特别之处,只需指定smtp服务器并发送即可

public static void SendWithSMTP(string name, string pass, string host, int port)
{
    using (var client = new System.Net.Mail.SmtpClient(host, port))
    {
        client.Credentials = new System.Net.NetworkCredential(name, pass);
        client.EnableSsl = true;
        MailMessage mail = new MailMessage("from@ex.com","to@ex.com",head, body);
        mail.Attachments.Add(new Attachment("specify your attachment path"));
        client.Send(mail);
    }
}

您可以发送文件url并请求用户下载文件。

SMTP的问题是您无法使用更安全的EC2Role。您必须嵌入凭据。这不是最好的做法。
您必须使用SendRawEmail

您使用SES发送电子邮件的方式与使用C#发送任何其他电子邮件的方式相同。您需要发布C代码、可能从代码中收到的具体问题和具体错误。谢谢。我想要代码发送电子邮件与附件谢谢。我已经编码发送电子邮件没有附件。我需要一封带有附件的电子邮件。我的示例中有附件。对不起。我没有注意到。让我试试。ThanksI收到异常“发送邮件失败”。内部异常为“无法从传输连接读取数据:net\u io\u connectionclosed.”。你能帮忙吗?
public static void SendWithSMTP(string name, string pass, string host, int port)
{
    using (var client = new System.Net.Mail.SmtpClient(host, port))
    {
        client.Credentials = new System.Net.NetworkCredential(name, pass);
        client.EnableSsl = true;
        MailMessage mail = new MailMessage("from@ex.com","to@ex.com",head, body);
        mail.Attachments.Add(new Attachment("specify your attachment path"));
        client.Send(mail);
    }
}