Wednesday, August 29, 2012

Mail Sending in asp.net

 <system.net>
    <mailSettings>
      <smtp>
        <network host="smtp.gmail.com" port="25" userName="emai address" password="emaipassword"/>
      </smtp>
    </mailSettings>
  </system.net>
<appsettings>
<add  key="Mail From" value=" From Email Address"/>
<add  key="Mail From Name" value=" From Name"/>
</appsettings>
 private void SendConfirmMail(string GroupName,string AccountName,string Email,string RoleName)
        {
                System.Net.Mail.MailMessage iMailMessage = new System.Net.Mail.MailMessage();
                SmtpClient smtp = new SmtpClient();
                if (ConfigurationManager.AppSettings["MailFrom"] != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<div style=\"display: block; background: #FFFFFF; width: 650px; float: left; border: 10px solid #ccc;\">");
                    sb.Append("<table style=\"font-family:Arial; font-size:12px;\"><tr><td>");
                    sb.Append("<img alt=\"Activayt\" src=\"http://202.53.10.34:591/images/logo-new.png\" width=\"250px\" height=\"64px\" border=\"none\"/></td></tr><tr><td><br />");
                    sb.Append("<div style=\"width: auto; line-height: 23px; min-width: 104px; height: 24px; background: #3DADE1; ");
                    sb.Append("font-family: Arial; font-size: 13px; font-weight: bold; text-align: left; color: #FFFFFF; ");
                    sb.Append("vertical-align: middle; float: left; padding: 0px 15px 0px 15px;line-height:13.25px;\">Added to <strong>" + GroupName + "</strong> as    " + RoleName + "</div></td></tr><tr>");
                    sb.Append("<td>&nbsp;&nbsp;&nbsp;Dear <strong> &nbsp;"+ Email +"&nbsp; </strong> ,</td></tr><tr><td>");
                    sb.Append("The &nbsp;&nbsp;<strong>Account Manager</strong>&nbsp;&nbsp;of &nbsp;&nbsp;&nbsp;<strong>" + AccountName + "</strong>&nbsp;&nbsp;&nbsp; has been added you on Activayt.com as Group" + RoleName + ".</td></tr></table>");
                    sb.Append("<table width=\"650px\" style=\"font-family:Arial; font-size:12px;\"><tr><td><strong></strong></td>");
                    sb.Append("<td></td><td></td></tr><tr><td><strong></strong></td><td></td>");
                    sb.Append("<td></td></tr><tr><td><strong></strong></td><td></td><td></td></tr></table>");
                    sb.Append("<table width=\"650px\" style=\"font-family:Arial; font-size:12px;\"><tr><td>");
                    sb.Append("&nbsp;&nbsp;&nbsp;Please <a href=\"http://202.53.10.34:591/UseCaseHelp.aspx?RN=" + Crypto.ActionEncrypt(RoleName) + "\" style=\"color: #0000cc;\" target=\"_blank\">Click Here</a> to Start exploring your new role on Activayt.com</td></tr><tr><td><br />");
                    sb.Append("&nbsp;Thanks &amp; Regards</td></tr><tr><td>&nbsp;Activayt  Team</td></tr></table></div>");
                    iMailMessage.From = new MailAddress(ConfigurationManager.AppSettings["MailFrom"].ToString(), ConfigurationManager.AppSettings["MailFromName"].ToString());
                    iMailMessage.To.Add(new MailAddress(Email));
                    iMailMessage.IsBodyHtml = true;
                    iMailMessage.Body = sb.ToString();
                    iMailMessage.Subject = "You are added as a Group  " + ObjGroupDO.Role;
                    smtp.Send(iMailMessage);
                }
                else
                {

                }
        }

No comments:

Post a Comment