-5

我正在使用 Amazon SES 发送电子邮件。如何使用 Amazon SES 在 C# 中发送带附件的电子邮件?

代码:

            AmazonSimpleEmailServiceConfig amConfig = new AmazonSimpleEmailServiceConfig();
            amConfig.UseSecureStringForAwsSecretKey = false;
            AmazonSimpleEmailServiceClient amzClient = new AmazonSimpleEmailServiceClient("username", "password", amConfig);
            ArrayList to = new ArrayList();                        
            to.Add("sharmila@test.com");

            Destination dest = new Destination();
            dest.WithBccAddresses((string[])to.ToArray(typeof(string)));
            string body = "INSERT HTML BODY HERE";
            string subject = "INSERT EMAIL SUBJECT HERE";
            Body bdy = new Body();
            bdy.Html = new Amazon.SimpleEmail.Model.Content(body);
            Amazon.SimpleEmail.Model.Content title = new Amazon.SimpleEmail.Model.Content(subject);
            Message message = new Message(title, bdy);
            SendEmailRequest ser = new SendEmailRequest("websupport@test.com", dest, message);
            SendEmailResponse seResponse = amzClient.SendEmail(ser);
            SendEmailResult seResult = seResponse.SendEmailResult; 
4

3 回答 3

2

Amazon SES 没有什么特别之处,只需指定您的 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);
    }
}
于 2012-03-18T04:08:19.520 回答
0

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

于 2020-03-02T14:09:52.787 回答
-2

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

于 2012-10-27T11:36:10.877 回答