Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:43:43+00:00 2026-06-11T20:43:43+00:00

I want to send email with alternate views either plain text or html template,

  • 0

I want to send email with alternate views either plain text or html template, i have used code from the following link
aspnet-sending-email-both-in-html-and-plain-text but i dont know why its not working for me.. my code is:.

  public void EmailSendingWithBothHTMLAndPlainText()
{
    // CREATE EMAIL
    // first we create a plain text version and set it to the AlternateView
    // then we create the HTML version
    System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

    msg.From = new MailAddress("visionstask@gmail.com");
    msg.Subject = "Event: testing";
    msg.To.Add("ram@tsgdev.net");

    // create a string to hold all email addresses
    StringBuilder sbEmailTo = new StringBuilder();
    sbEmailTo.Append("visionstask@gmail.com");

    //if (!String.IsNullOrEmpty(TextBoxEmail2.Text)) { msg.To.Add(TextBoxEmail2.Text); sbEmailTo.Append(", " + TextBoxEmail2.Text); }
    //if (!String.IsNullOrEmpty(TextBoxEmail3.Text)) { msg.To.Add(TextBoxEmail3.Text); sbEmailTo.Append(", " + TextBoxEmail3.Text); }
    //if (!String.IsNullOrEmpty(TextBoxEmail4.Text)) { msg.To.Add(TextBoxEmail4.Text); sbEmailTo.Append(", " + TextBoxEmail4.Text); }
    //if (!String.IsNullOrEmpty(TextBoxEmail5.Text)) { msg.To.Add(TextBoxEmail5.Text); sbEmailTo.Append(", " + TextBoxEmail5.Text); }



    //now create the HTML version
    MailDefinition message = new MailDefinition();
    message.BodyFileName = "RegisterUser.html";
    message.IsBodyHtml = true;
    message.From = "visionstask@gmail.com";
    message.Subject = "Zoo Event: " + "testing for HTML";

    //embed images for the email
    //EmbeddedMailObject emo = new EmbeddedMailObject();
    //emo.Path = @"~\Images\email\hdr_roar.gif";
    //emo.Name = "hdr";

    //EmbeddedMailObject emo2 = new EmbeddedMailObject();
    ////emo2.Path = @"~\Images\email\box_top.gif";
    //emo2.Name = "box_top";

    //message.EmbeddedObjects.Add(emo);
    //message.EmbeddedObjects.Add(emo2);

    //Build replacement collection to replace fields in email.htm file
    ListDictionary replacements = new ListDictionary();
    replacements.Add("@Name", "Ram Singh");


    //now create mail message using the mail definition object
    //the CreateMailMessage object takes a source control object as the last parameter,
    //if the object you are working with is webcontrol then you can just pass "this",
    //otherwise create a dummy control as below.
    //System.Net.Mail.MailMessage msgHtml = message.CreateMailMessage(sbEmailTo.ToString(), replacements, new LiteralControl());

    //AlternateView htmlView = AlternateView.CreateAlternateViewFromString(msgHtml.Body, null, "text/html");


    // msg.AlternateViews.Add(htmlView);


    String plainEmail = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center'><table width='600' bgcolor='#f3f3f3' border='0' cellpadding='0' cellspacing='0'><tr><td><img src='http://localhost:4823/WishIsDone/Images/emaillogo.png' style='margin-left: 50px;'alt='' /></td></tr><tr><td><table bgcolor='#FFFFFF' border='0' width='500' align='center' style='margin: auto; border: 1px solid #999; padding: 5px;' cellpadding='0' cellpadding='0'><tr><td style='font-size: 18px; font-family: Verdana, Geneva, sans-serif; color: #008fbb;'>Registration</td></tr></table></td></tr><tr><td><table bgcolor='#FFFFFF' border='0' width='500' align='center' style='margin: auto; border: 1px solid #999; padding: 20px;'><tr><td>Hello @Name!</td></tr><tr><td style='font-size: 11px; font-family: Verdana, Geneva, sans-serif;'>Welcome to WishIsDone Website </td></tr><tr><td style='font-size: 12px; color: #008fbb; font-family: Verdana, Geneva, sans-serif;'> <p>You have successfully registrated.</p> </td> </tr><tr><td style='font-size: 11px; font-family: Verdana, Geneva, sans-serif; color: #999;'><p>Verify your e-mail address to complete your registration by clicking the link:</p> <p><a href='#'>@link</a></p><p><strong style='color: #000; font-size: 10px; font-weight: bold;'>Note:</strong><span style='color: #333;'>please change your password after login.</span></p><table style='border-top: 1px dotted #999; margin: auto;' width='450'><tr><td style='font-size: 10px; color: #333;'><p>Regards,<br /> Wish Is Done Team</p></td></tr></table></td></tr> </table> </td></tr> <tr> <td style='font-size: 10px; color: #333; padding: 10px 50px; font-family: Verdana, Geneva, sans-serif;'> <p> For any queries or difficulties Contact:<br /> Email:<a href='#'>info@wishisdone.com</a><br /> Toll free: XXX-XXX-XXXX<br /> <a href='#'>www.wishisdone.com</a></p> </td></tr><tr><td><table style='border-top: 1px dotted #999; width: 500px; color: #333; margin: auto; font-size: 9px; font-family: Verdana, Geneva, sans-serif;'> <tr><td>Copyright &copy; 2012 wishisdone</td></tr></table></td></tr></table></td> </tr></table>";

    //first we create the Plain Text part
    AlternateView plainView = AlternateView.CreateAlternateViewFromString(plainEmail, null, "text/plain");
    msg.AlternateViews.Add(plainView);
    msg.IsBodyHtml = true;
    SmtpClient emailClient = new SmtpClient("smtp.gmail.com");
    System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("test@gmail.com", "test");
    emailClient.UseDefaultCredentials = false;
    emailClient.Credentials = SMTPUserInfo;
    emailClient.Port = 587;
    emailClient.EnableSsl = true;
    //SmtpClient emailClient = new SmtpClient(ConfigurationManager.AppSettings["SMTP"].ToString());
    //emailClient.UseDefaultCredentials = false;
    //emailClient.EnableSsl = true;

    emailClient.Send(msg);
}

and i am getting the following outout in mail :

<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center'><table width='600' bgcolor='#f3f3f3' border='0' cellpadding='0' cellspacing='0'><tr><td><img src='http://localhost:4823/WishIsDone/Images/emaillogo.png' style='margin-left: 50px;'alt='' /></td></tr><tr><td><table bgcolor='#FFFFFF' border='0' width='500' align='center' style='margin: auto; border: 1px solid #999; padding: 5px;' cellpadding='0' cellpadding='0'><tr><td style='font-size: 18px; font-family: Verdana, Geneva, sans-serif; color: #008fbb;'>Registration</td></tr></table></td></tr><tr><td><table bgcolor='#FFFFFF' border='0' width='500' align='center' style='margin: auto; border: 1px solid #999; padding: 20px;'><tr><td>Hello @Name!</td></tr><tr><td style='font-size: 11px; font-family: Verdana, Geneva, sans-serif;'>Welcome to WishIsDone Website </td></tr><tr><td style='font-size: 12px; color: #008fbb; font-family: Verdana, Geneva, sans-serif;'> <p>You have successfully registrated.</p> </td> </tr><tr><td style='font-size: 11px; font-family: Verdana, Geneva, sans-serif; color: #999;'><p>Verify your e-mail address to complete your registration by clicking the link:</p> <p><a href='#'>@link</a></p><p><strong style='color: #000; font-size: 10px; font-weight: bold;'>Note:</strong><span style='color: #333;'>please change your password after login.</span></p><table style='border-top: 1px dotted #999; margin: auto;' width='450'><tr><td style='font-size: 10px; color: #333;'><p>Regards,<br /> Wish Is Done Team</p></td></tr></table></td></tr> </table> </td></tr> <tr> <td style='font-size: 10px; color: #333; padding: 10px 50px; font-family: Verdana, Geneva, sans-serif;'> <p> For any queries or difficulties Contact:<br /> Email:<a href='#'>info@wishisdone.com</a><br /> Toll free: XXX-XXX-XXXX<br /> <a href='#'>www.wishisdone.com</a></p> </td></tr><tr><td><table style='border-top: 1px dotted #999; width: 500px; color: #333; margin: auto; font-size: 9px; font-family: Verdana, Geneva, sans-serif;'> <tr><td>Copyright &copy; 2012 wishisdone</td></tr></table></td></tr></table></td> </tr></table>

Please help me..i want to display it the well formatted way, because of that i want to use alternate views.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:43:44+00:00Added an answer on June 11, 2026 at 8:43 pm

    Try to use text/html as mime type when creating the alternate view:

    AlternateView plainView = AlternateView.CreateAlternateViewFromString(plainEmail, null, "text/html");
    

    Like it´s done int this example:
    Alternate Views

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF web service. I want to send email from this service.
I want to send email through Java (Any email like from yahoo, gmail, or
I want to send an email from within my iPhone application, primarily because i
i want to send an email to user after he sign-up with code.for ex
I am trying to send and email text or/and html versions.. What I do
I want to send email messages that have arbitrary unicode bodies in a Python
i'm using the following code on my php page to send an email with
I want to send email from my application without configuration email in android device.
I want to send html email's with my Rails Mailer. Could be multipart/alternative or
I want to send email from my .net application. Please tell me the steps

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.