Pages - Menu

Tuesday 18 February 2014

Send Registration email using .net


Html format for sending registration mail using SMTP server C#

Step1:- Create a file mail.aspx and put the code on mail.aspx.cs

Include name spaces

using System.Net.Mail;
using System.Web.Mail;

copy the code and paste it on button click event.
protected void btnSubmit_Click(object sender, EventArgs e)
{
// Create a new message
var mail = new MailMessage();

// Set the to and from addresses.
// The from address must be your GMail account
mail.From = new MailAddress("example@gmail.com");
mail.To.Add(new MailAddress(to));

// Define the message
mail.Subject = “Thank you for register at devssolution.com”;
mail.IsBodyHtml =true;
mail.Body = "<br/><div " +
"style=color: rgb(69, 69, 69); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px;" +
"font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal;" +
"orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto;" +
"word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); width: 560px; " +
"padding-top: 50px; height: 100px; margin: 0px auto;>" +
"<a href=http://devssolution.blogspot.com/><img  alt=Ads height=53 " +
"src=www.devssolution.blogspot.com/images/logo.png " +
"style=border: none; display: block; /></a></div>" +
"<table  bgcolor=#ffffff border=0 " +
"cellpadding=0 cellspacing=0 " +
"style=padding: 0px; display: table; border-collapse: separate; color: rgb(69, 69, 69);" +
"font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 12px; font-style: normal; " +
"font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto;" +
"text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; " +
"width=100%>" +
"<tbody  style=width: 870px;>" +
"<tr" +
"style=display: table-row; vertical-align: inherit;>" +
"<td " +
"style=display: table-cell; border-spacing: 2px;>" +
"&nbsp;</td>" +
"<td " +
"style=display: table-cell; border-spacing: 2px; width: 536px;>" +
"<table  border=0 cellpadding=0 " +
"cellspacing=0 " +
"style=padding: 0px; display: table; border-collapse: collapse; border: none; " +
"width=100%>" +
"<tbody style=width: 536px;>" +
"<tr " +
"style=display: table-row; vertical-align: inherit;>" +
"<td  height=25 " +
"style=display: table-cell; border-spacing: 2px;>" +
"</td>" +
"</tr>" +
"<tr " +
"style=display: table-row; vertical-align: inherit;>" +
"<td " +
"style=display: table-cell; border-spacing: 2px; width: 536px;>" +
"<table " +
"style=padding: 0px; display: table; border-collapse: separate;" +
"border-left-width: 1px; border-left-style: solid; " +
"border-left-color: rgb(204, 204, 204); border-right-width: 1px; " +
"border-right-style: solid; border-right-color: rgb(204, 204, 204);" +
"width: 536px; height: 200px;>" +
"<tbody  style=width: 534px;>" +
"<tr " +
"style=display: table-row; vertical-align: inherit;>" +
"<td " +
"style=display: table-cell; border-spacing: 2px;>" +
"<div " +
"style=padding: 0px 40px; width: 448px;>" +
"<p style=margin: 0px; padding: 0px; display: block;" +
"line-height: normal; font-style: normal; " +
"font-variant: normal; font-size: 15px; font-family: Arial;" +
"font-weight: bold; color: rgb(102, 102, 102);>"+
"Dear Valued Customer " + "</p>" +
"" +
"<p style=margin: 0px; padding: 0px; display: block;" +
"line-height: 14px; font-style: normal; font-variant: normal;" +
"font-weight: normal; font-size: 12px; font-family: Arial;" +
"color: rgb(102, 102, 102);>" +
"Thank you for using devssolution!  <br/>" +
"<span class=Apple-converted-space>&nbsp;</span><br/>Following are the login details for your account on Adssledeger" +
//+" We have forwarded your query to the concerned department.<br/> Within 48 hours , a Customer Relationship Officer will contact you.</p>" +
"<br /><br /><strong>Login ID:" + "      " + name +
"</strong><br><strong>Password:" + "       " + passwords + "</strong><span " +
"class=Apple-converted-space>&nbsp;</span><br />" +
"<br />" +
"Thanks again and we look forward to serve you."+
"<p style=margin: 0px; padding: 0px; display: block; line-height: normal;>" +
"<em><strong >The DevsSolution Team</strong></em><br />" +
"</p>" +
"</div>" +
"</td>" +
"</tr>" +
"</tbody>" +
"</table>" +
"</td>" +
"</tr>" +
"<tr style=display: table-row; vertical-align: inherit;>" +
"<td style=display: table-cell; border-spacing: 2px;>" +
"<div>" +
"</div>" +
"</td>" +
"</tr>" +
"</tbody>" +
"</table>" +
"<div " +
"style=border-top-width: 1px; border-top-style: solid; border-top-color: rgb(204, 204, 204);" +
"padding: 10px 10px 10px 40px; text-align: center; font-style: normal; font-variant: normal;" +
"font-weight: normal; font-size: 11px; line-height: normal; font-family: Arial; color: rgb(153, 153, 153);" +
"width: 400px; height: 120px; margin: 40px auto 0px;>" +
"devssolution. | 1 Richmond Street New Brunswick | New Jersey 08901<br />" +
"<a href=devssolution.blogspot.com>www.devsolution.com</a></br>" +
"<div " +
"style=background-image: url(images/logo.png); height: 248px; background-position: initial initial; background-repeat: initial initial;>" +
"&nbsp;</div>" +
"</td>" +
"</tr>" +
"</tbody>" +
"</table>";;

// Create a new Smpt Client using Google's servers
var mailclient = new SmtpClient();
mailclient.Host = "smtp.gmail.com";
mailclient.Port = 587;

// This is the critical part, you must enable SSL
mailclient.EnableSsl = true;

// Specify your authentication details
mailclient.Credentials = new System.Net.NetworkCredential(
"YOUR GMAIL USERNAME",
"YOUR GMAIL PASSWORD");
mailclient.Send(mail);

    }

Note: Using only gmail credentials. If you want to use your  hotmail account or other change the port no. 587 port no is only use for gmail account.

1 comment: