-5

I am using Amazon SES to send email. How to send email with attachment in C# using Amazon SES?

Code:

            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; 
Blachshma
  • 16,379
  • 4
  • 51
  • 66
sharmila
  • 29
  • 3
  • 7
  • 1
    You send e-mail with SES the same way you'd send any other e-mail in C#. You need to post the C# code, specific questions and specific errors you might be receiving from your code. – paulsm4 Mar 18 '12 at 04:08
  • Thanks. I want code to send email with attachment – sharmila Mar 18 '12 at 04:12

3 Answers3

2

Nothing special about Amazon SES, just specify your smtp server and send it.

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);
    }
}
emre nevayeshirazi
  • 17,877
  • 11
  • 57
  • 77
0

The problem with SMTP is you cannot use a more secure EC2Role. You have to embed credentials. Not a best practice. You have to use a SendRawEmail

Robert
  • 1
-2

You can send the file url and request the user to download the file.

Bo Persson
  • 86,087
  • 31
  • 138
  • 198
susheel
  • 15
  • 1