2012-03-18 105 views
-5

我正在使用Amazon SES發送電子郵件。如何使用Amazon SES在C#中使用附件發送電子郵件?使用Amazon SES在C#中使用附件發送電子郵件

代碼:

  AmazonSimpleEmailServiceConfig amConfig = new AmazonSimpleEmailServiceConfig(); 
      amConfig.UseSecureStringForAwsSecretKey = false; 
      AmazonSimpleEmailServiceClient amzClient = new AmazonSimpleEmailServiceClient("username", "password", amConfig); 
      ArrayList to = new ArrayList();       
      to.Add("[email protected]"); 

      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("[email protected]", dest, message); 
      SendEmailResponse seResponse = amzClient.SendEmail(ser); 
      SendEmailResult seResult = seResponse.SendEmailResult; 
+1

您使用SES發送電子郵件的方式與使用C#發送其他電子郵件的方式相同。您需要發佈C#代碼,具體問題以及您可能從代碼中收到的特定錯誤。 – paulsm4 2012-03-18 04:08:22

+0

謝謝。我想要代碼發送電子郵件附件 – sharmila 2012-03-18 04:12:50

回答

1

沒有什麼特別之處亞馬遜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("[email protected]","[email protected]",head, body); 
     mail.Attachments.Add(new Attachment("specify your attachment path")); 
     client.Send(mail); 
    } 
} 
+0

謝謝。我編碼發送電子郵件沒有附件。我需要電子郵件附件 – sharmila 2012-03-18 04:13:43

+2

有我的例子中的附件。 – 2012-03-18 04:14:54

+0

對不起。我沒有注意到。讓我嘗試。謝謝 – sharmila 2012-03-18 04:20:32

-2

您可以發送文件url並請求用戶下載文件。

相關問題