Send Email From Amazon SES in ASP.NET MVC App

Viewed 9944

I host my web app which is written in .net mvc2 on amazon ec2. currrently use gmail smtp to send email. beacuse of google for startup email quota cant send more than 500 email a day. So decide to move amazon ses. How can use amazon ses with asp.net mvc2? How about configuration etc? Is email will send via gmail? because our email provider is gmail. etc.

5 Answers

Following is how I sent email with attachment

  public static void SendMailSynch(string file1, string sentFrom, List<string> recipientsList, string subject, string body)
    {

        string smtpClient = "email-smtp.us-east-1.amazonaws.com"; //Correct it
        string conSMTPUsername = "<USERNAME>";
        string conSMTPPassword = "<PWD>";

        string username = conSMTPUsername;
        string password = conSMTPPassword;

        // Configure the client:
        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(smtpClient);
        client.Port = 25;
        client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;

        System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(username, password);
        client.EnableSsl = true;
        client.Credentials = credentials;

        // Create the message:
        var mail = new System.Net.Mail.MailMessage();
        mail.From = new MailAddress(sentFrom);
        foreach (string recipient in recipientsList)
        {
            mail.To.Add(recipient);
        }
        mail.Bcc.Add("test@test.com");
        mail.Subject = subject;
        mail.Body = body;
        mail.IsBodyHtml = true;


        Attachment attachment1 = new Attachment(file1, MediaTypeNames.Application.Octet);


        ContentDisposition disposition = attachment1.ContentDisposition;
        disposition.CreationDate = System.IO.File.GetCreationTime(file1);
        disposition.ModificationDate = System.IO.File.GetLastWriteTime(file1);
        disposition.ReadDate = System.IO.File.GetLastAccessTime(file1);

        mail.Attachments.Add(attachment1);

        client.Send(mail);
    }
Related