【问题标题】:Sending html template via amazon ses通过亚马逊 ses 发送 html 模板
【发布时间】:2013-07-31 09:27:15
【问题描述】:

我正在使用以下代码发送计划文本,但它在 html 模板中不起作用..

    static void Main(string[] args)
    {
        String username = "test";  // Replace with your SMTP username.
        String password = "test";  // Replace with your SMTP password.
        String host = "email-smtp.us-east-1.amazonaws.com";
        int port = 25;

        using (var client = new System.Net.Mail.SmtpClient(host, port))
        {
            client.Credentials = new System.Net.NetworkCredential(username, password);
            client.EnableSsl = true;

            client.Send
            (
                      "sales@imagedb.com",  // Replace with the sender address.
                      "rohit@imagedb.com",    // Replace with the recipient address.
                      "Testing Amazon SES through SMTP",
                      "This email was delivered through Amazon SES via the SMTP end point."
            );
        }

【问题讨论】:

    标签: c# .net amazon amazon-ses


    【解决方案1】:

    您需要将AlternateViews 与.NET SmtpClient 一起使用来发送HTML 消息。邮件客户端将呈现它可以支持的适当视图。

    这是一个代码 sn-p,它演示了如何使用文本视图和 HTML 视图创建消息,然后通过 Amazon SES 发送消息。

            string host = "email-smtp.us-east-1.amazonaws.com";
            int port = 25;
    
            var credentials = new NetworkCredential("ses-smtp-username", "ses-smtp-password");
            var sender = new MailAddress("sender@example.com", "Message Sender");
            var recipientTo = new MailAddress("recipient+one@example.com", "Recipient One");
            var subject = "HTML and TXT views";
    
            var htmlView = AlternateView.CreateAlternateViewFromString("<p>This message is <code>formatted</code> with <strong>HTML</strong>.</p>", Encoding.UTF8, MediaTypeNames.Text.Html);
            var txtView = AlternateView.CreateAlternateViewFromString("This is a plain text message.", Encoding.UTF8, MediaTypeNames.Text.Plain);
    
            var message = new MailMessage();
            message.Subject = subject;
            message.From = sender;
            message.To.Add(recipientTo);
            message.AlternateViews.Add(txtView);
            message.AlternateViews.Add(htmlView);
    
            using (var client = new SmtpClient(host, port))
            {
                client.Credentials = credentials;
                client.EnableSsl = true;
    
                client.Send(message);
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-15
      • 1970-01-01
      • 2019-05-08
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 2013-01-27
      • 1970-01-01
      相关资源
      最近更新 更多