protected void btnSendLoginWidGet_Click(object sender, EventArgs e) { Emailer emailer = new Emailer(); EmailMessage email = new EmailMessage(); AdviserStaffSMTPBo adviserStaffSMTPBo = new AdviserStaffSMTPBo(); AdviserStaffSMTPVo adviserStaffSMTPVo = new AdviserStaffSMTPVo(); string logoPath = string.Empty; bool isMailSent = false; email.GetAdviserLoginWidgetMail(Encryption.Encrypt(adviserVo.advisorId.ToString()), adviserVo.OrganizationName.Trim()); email.To.Add(txtLoginWidGetEmail.Text.Trim()); adviserStaffSMTPVo = adviserStaffSMTPBo.GetSMTPCredentials(1000); if (adviserStaffSMTPVo.HostServer != null && adviserStaffSMTPVo.HostServer != string.Empty) { emailer.isDefaultCredentials = !Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired); if (!String.IsNullOrEmpty(adviserStaffSMTPVo.Password)) { emailer.smtpPassword = Encryption.Decrypt(adviserStaffSMTPVo.Password); } emailer.smtpPort = int.Parse(adviserStaffSMTPVo.Port); emailer.smtpServer = adviserStaffSMTPVo.HostServer; emailer.smtpUserName = adviserStaffSMTPVo.Email; email.Body = email.Body.Replace("[ORGANIZATION]", "WealthERP Team"); if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") { email.Body = email.Body.Replace("[WEBSITE]", "https://app.wealtherp.com/"); } email.Body = email.Body.Replace("[CONTACTPERSON]", "Mr Vijay Shenoy"); email.Body = email.Body.Replace("[DESIGNATION]", "Customer Care"); email.Body = email.Body.Replace("[PHONE]", "080 - 32429514"); email.Body = email.Body.Replace("[EMAIL]", "*****@*****.**"); email.Body = email.Body.Replace("[LOGO]", "<img src='cid:HDIImage' alt='Logo'>"); System.Net.Mail.AlternateView htmlView; System.Net.Mail.AlternateView plainTextView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("Text view", null, "text/plain"); //System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(hidBody.Value.Trim() + "<image src=cid:HDIImage>", null, "text/html"); htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<html><body " + "style='font-family:Tahoma, Arial; font-size: 10pt;'><p>" + email.Body + "</p></body></html>", null, "text/html"); //Add image to HTML version logoPath = "~/Images/WealthERP.jpf"; if (!File.Exists(Server.MapPath(logoPath))) { logoPath = "~/Images/spacer.png"; } //System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(Server.MapPath("~/Images/") + @"\3DSYRW_4009.JPG", "image/jpeg"); System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(Server.MapPath(logoPath), "image/jpeg"); imageResource.ContentId = "HDIImage"; htmlView.LinkedResources.Add(imageResource); //Add two views to message. email.AlternateViews.Add(plainTextView); email.AlternateViews.Add(htmlView); //Send message //System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(); //Assign SMTP Credentials if configured. if (adviserStaffSMTPVo.HostServer != null && adviserStaffSMTPVo.HostServer != string.Empty) { emailer.isDefaultCredentials = !Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired); if (!String.IsNullOrEmpty(adviserStaffSMTPVo.Password)) { emailer.smtpPassword = Encryption.Decrypt(adviserStaffSMTPVo.Password); } emailer.smtpPort = int.Parse(adviserStaffSMTPVo.Port); emailer.smtpServer = adviserStaffSMTPVo.HostServer; emailer.smtpUserName = adviserStaffSMTPVo.Email; if (Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired)) { if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") { email.From = new MailAddress(emailer.smtpUserName, "WealthERP Team"); } } } isMailSent = emailer.SendMail(email); if (isMailSent) { trSuccessMsg.Visible = true; //tblErrorMassage.Visible = false; divSuccessMsg.InnerText = "Login Widget send to this email Id"; } else { trSuccessMsg.Visible = false; //tblErrorMassage.Visible = true; divSuccessMsg.InnerText = "An error occurred while sending Login Widget"; } } }