Format the emails using StringBulider in asp.net | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Format the emails using StringBulider in asp.net

Introduction: In this article today I am going to explain how we can format the emails using Stringbulider in asp.net

Description:

Firstly check this article Send email in asp.net

Add a wedform to project and design the page as shown below:

  <fieldset style="width:400px">
    <legend>Format the Emails using StringBuilder Example</legend>
    <table>
    <tr><td>Email Sent To :</td><td>  <asp:TextBox ID="txtemail" runat="server"></asp:TextBox></td></tr>
    <tr><td></td><td><asp:Button ID="btnsend" runat="server" Text="Send Email" onclick="Button1_Click" /></td></tr>   
    <tr><td></td><td><label id="lblmessage" runat="server"></label></td></tr>
    </table>
    </fieldset>

On button click write the below given code (C#):
using System.Net.Mail;

protected void Button1_Click(object sender, EventArgs e)
        {       
         sendemail();
        }

        public void sendemail()
        {
            try
            {
                System.Text.StringBuilder mailBody = new System.Text.StringBuilder();
                mailBody.Append("<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"4\" cellspacing=\"2\" style=\"font-family:Arial,Verdana\"> ");
                mailBody.Append("<tr>");
                mailBody.Append("<td style='background-color: #f4d687'>");
                mailBody.Append("Welcome to Articlemirror,");
                mailBody.Append("</tr>");
                mailBody.Append("</td>");
                mailBody.Append("<tr><td><img src= \"http://1.bp.blogspot.com/-KVkKmUPkM8M/Uv8SYZ9WCKI/AAAAAAAAA9Q/PienHthBOYU/s1600/am3.png\" /></td></tr>");
                mailBody.Append("<tr><td>Thank you for joining us. You are the Mebmer of Articlemirror.</td></tr>");
                mailBody.Append("<tr><td><a href=\"http://articlemirror.blogspot.in\">Click here to go Your Webiste</a></td></tr>");
                mailBody.Append("<tr><td></td><td><b>Regards,</b></td></tr>");
                mailBody.Append("<tr><td></td><td style='background-color: #0696AF;color:#ffffff'><b>Article Mirror</b></td></tr>");
                mailBody.AppendLine("</table>");
                string Email = ConfigurationManager.AppSettings["Email"].ToString();
                string Emailto = txtemail.Text;
                MailMessage mail = new MailMessage(Email, Emailto);
                mail.Subject = "Article Mirror";
                mail.Body = mailBody.ToString();
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Send(mail);
                lblmessage.InnerText ="Email send successfully";
                txtemail.Text = "";

            }
            catch (Exception ex)
            {
            }         
        }
In VB:
Imports System.Net.Mail

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnsend.Click
        sendemail()
    End Sub

    Public Sub sendemail()
        Try
            Dim mailBody As New System.Text.StringBuilder()
            mailBody.Append("<table width=""100%"" border=""0"" align=""center"" cellpadding=""4"" cellspacing=""2"" style=""font-family:Arial,Verdana""> ")
            mailBody.Append("<tr>")
            mailBody.Append("<td style='background-color: #f4d687'>")
            mailBody.Append("Welcome to Articlemirror,")
            mailBody.Append("</tr>")
            mailBody.Append("</td>")
            mailBody.Append("<tr><td><img src= ""http://1.bp.blogspot.com/-KVkKmUPkM8M/Uv8SYZ9WCKI/AAAAAAAAA9Q/PienHthBOYU/s1600/am3.png"" /></td></tr>")
            mailBody.Append("<tr><td>Thank you for joining us. You are the Mebmer of Articlemirror.</td></tr>")
            mailBody.Append("<tr><td><a href=""http://articlemirror.blogspot.in"">Click here to go Your Webiste</a></td></tr>")
            mailBody.Append("<tr><td></td><td><b>Regards,</b></td></tr>")
            mailBody.Append("<tr><td></td><td style='background-color: #0696AF;color:#ffffff'><b>Article Mirror</b></td></tr>")
            mailBody.AppendLine("</table>")
            Dim Email As String = ConfigurationManager.AppSettings("Email").ToString()
            Dim Emailto As String = txtemail.Text
            Dim mail As New MailMessage(Email, Emailto)
            mail.Subject = "Article Mirror"
            mail.Body = mailBody.ToString()
            mail.IsBodyHtml = True
            Dim smtp As New SmtpClient()
            smtp.Send(mail)
            lblmessage.InnerText = "Email send successfully"
        Catch ex As Exception
        End Try
    End Sub
Build the project and test.
Output:
Format the emails using Stringbulider in asp.net



Is this article helpful for you?
If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget