使用Amazon SES在C#中发送带附件的电子邮件

时间:2012-03-18 04:02:39

标签: c# amazon-ses

我正在使用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; 

3 个答案:

答案 0 :(得分: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);
    }
}

答案 1 :(得分:0)

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

答案 2 :(得分:-2)

您可以发送文件网址并请求用户下载该文件。