c# - Sending html template via amazon ses -


i'm using below code send plan text it's not working in html template..

    static void main(string[] args)     {         string username = "test";  // replace smtp username.         string password = "test";  // replace 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 sender address.                       "rohit@imagedb.com",    // replace recipient address.                       "testing amazon ses through smtp",                       "this email delivered through amazon ses via smtp end point."             );         } 

you need use alternateviews .net smtpclient send html messages. mail client render appropriate views can support.

here code snippet demonstrates how create message text view , html view, , send message via 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 , txt views";          var htmlview = alternateview.createalternateviewfromstring("<p>this message <code>formatted</code> <strong>html</strong>.</p>", encoding.utf8, mediatypenames.text.html);         var txtview = alternateview.createalternateviewfromstring("this 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);         } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -