/// <summary> /// Tranform email addresses given in web.conf into proper format /// </summary> /// <param name="EmailAddresses">Email Address in web.conf</param> /// <returns>formated email address to contact</returns> private string TranformEmailAddresses() { string ContactEmailAddressesTo = LACESUtilities.GetAdminToEmail(); string ContactEmailAddressesCC = LACESUtilities.GetAdminCCEmail(); string FormatedAddresses = ContactEmailAddressesTo.Replace(",", ";") + "?cc=" + ContactEmailAddressesCC; return(FormatedAddresses); }
/// <summary> /// Used to send mail when admin add a new provider or update an existing provider. /// Return true is send mail successfull, otherwise return false. /// </summary> /// <param name="isUpdate">True if provider update mode</param> /// <returns>Return true if send mail successfull</returns> private bool SendMailToProvider(bool isUpdate) { try { SmtpClient smtpClient = new SmtpClient(); //Get the SMTP server Address from SMTP Web.conf smtpClient.Host = LACESUtilities.GetApplicationConstants(LACESConstant.SMTPSERVER); //Get the SMTP port 25; smtpClient.Port = Convert.ToInt32(LACESUtilities.GetApplicationConstants(LACESConstant.SMTPPORT)); //create the message body MailMessage message = new MailMessage(); string adminToAddress = LACESUtilities.GetAdminToEmail().Replace(",", ";") + "?cc=" + LACESUtilities.GetAdminCCEmail(); string ToEmailAddress = Server.HtmlEncode(txtEmail.Text.Trim()); message.From = new MailAddress(LACESUtilities.GetAdminFromEmail()); message.To.Add(new MailAddress(txtEmail.Text.Trim())); message.Subject = "American Society of Landscape Architects:" + LACESConstant.LACES_TEXT + " Notification"; message.IsBodyHtml = true; string RefrenceURL = String.Empty; RefrenceURL = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf("/", Request.Url.AbsoluteUri.LastIndexOf("/") - 1)) + "/provider/" + LACESConstant.URLS.PROVIDER_LOGIN; //create the emailbody StringBuilder EmailBody = new StringBuilder(); EmailBody.Append("<html>"); EmailBody.Append("<head>"); EmailBody.Append("<title>Title</title>"); EmailBody.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"); EmailBody.Append("</head>"); EmailBody.Append("<body style=\"font-family: Arial, verdana, Helvetica, sans-serif; font-size:13px;\">"); string MailBody = ""; //if the provider is active if (radStatus.SelectedValue == "Y") { if (isUpdate) { MailBody = @"<div>Dear " + Server.HtmlEncode(txtOrganization.Text.Trim()) + ", </br></br> " + LACESConstant.LACES_TEXT + " admin updated your profile as an active provider. Your updated login information are as follows:</div></br>" + "<p><div>User Name: " + Server.HtmlEncode(txtEmail.Text.Trim()) + "</div>" + "<div>Password: "******"</div></p>" + "<p><div>You can access the " + LACESConstant.LACES_TEXT + " system at the following URL: " + "<a href=\"" + RefrenceURL + "\">" + RefrenceURL + "</a>.</p><p> If you require further assistance, please contact the " + LACESConstant.LACES_TEXT + " Administrators at the following email address: " + "<a href=\"mailto:" + adminToAddress + "\">" + LACESConstant.LACES_TEXT + " Administrators' Emails</a>.</p></div>"; } else { MailBody = @"<div>Dear " + Server.HtmlEncode(txtOrganization.Text.Trim()) + ", </br></br> " + LACESConstant.LACES_TEXT + " admin added you as an active provider. Your login information are as follows:</div></br>" + "<p><div>User Name: " + Server.HtmlEncode(txtEmail.Text.Trim()) + "</div>" + "<div>Password: "******"</div></p>" + "<p><div>You can access the " + LACESConstant.LACES_TEXT + " system at the following URL: " + "<a href=\"" + RefrenceURL + "\">" + RefrenceURL + "</a>.</p><p> If you require further assistance, please contact the " + LACESConstant.LACES_TEXT + " Administrators at the following email address: " + "<a href=\"mailto:" + adminToAddress + "\">" + LACESConstant.LACES_TEXT + " Administrators' Emails</a>.</p></div>"; } } //else if the provider is inactive else if (radStatus.SelectedValue == "N") { if (isUpdate) { MailBody = @"<div>Dear " + Server.HtmlEncode(txtOrganization.Text.Trim()) + ", </br></br> " + LACESConstant.LACES_TEXT + " admin updated your profile and set you as an inactive provider. Your login information are as follows:</div></br>" + "<p><div>User Name: " + Server.HtmlEncode(txtEmail.Text.Trim()) + "</div>" + "<div>Password: "******"</div></p>" + "<p><div>You can access the " + LACESConstant.LACES_TEXT + " system at the following URL when your account will be activated: " + "<a href=\"" + RefrenceURL + "\">" + RefrenceURL + "</a>.</p><p> If you require further assistance, please contact the " + LACESConstant.LACES_TEXT + " Administrators at the following email address: " + "<a href=\"mailto:" + adminToAddress + "\">" + LACESConstant.LACES_TEXT + " Administrators' Emails</a>.</p></div>"; } else { MailBody = @"<div>Dear " + Server.HtmlEncode(txtOrganization.Text.Trim()) + ", </br></br> " + LACESConstant.LACES_TEXT + " admin added you as an inactive provider. Your login information are as follows:</div></br>" + "<p><div>User Name: " + Server.HtmlEncode(txtEmail.Text.Trim()) + "</div>" + "<div>Password: "******"</div></p>" + "<p><div>You can access the " + LACESConstant.LACES_TEXT + " system at the following URL when your account will be activated: " + "<a href=\"" + RefrenceURL + "\">" + RefrenceURL + "</a>.</p><p> If you require further assistance, please contact the " + LACESConstant.LACES_TEXT + " Administrators at the following email address: " + "<a href=\"mailto:" + adminToAddress + "\">" + LACESConstant.LACES_TEXT + " Administrators' Emails</a>.</p></div>"; } } EmailBody.Append(MailBody); EmailBody.Append("</body>"); EmailBody.Append("</html>"); message.Body = EmailBody.ToString(); //finally send mail if (ConfigurationManager.AppSettings["SendOutgoingEmail"].ToString() == "Y") { smtpClient.Send(message); } return(true); } catch (Exception ex) { return(false); } }
/// <summary> /// Perform request course code type action on user button click /// Generates mail message /// Send mail to administrator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnRequest_Click(object sender, EventArgs e) { try { //Get current provider //Provider provider = (Provider)Session[LACESConstant.SessionKeys.LOGEDIN_PROVIDER]; ApprovedProvider provider = (ApprovedProvider)Session[LACESConstant.SessionKeys.LOGEDIN_APPROVED_PROVIDER]; // get approved provider information from Session //Set to email address //Declare new mail SmtpClient smtpCl = new SmtpClient(); MailMessage omsg = new MailMessage(); //MailMessage omsg.From = new MailAddress(LACESUtilities.GetAdminFromEmail()); omsg.To.Add(LACESUtilities.GetAdminToEmail()); omsg.CC.Add(LACESUtilities.GetAdminCCEmail()); //Set mail subject omsg.Subject = "New Course Code Requested"; //Set HTML mail format omsg.IsBodyHtml = true; string mailBody = Server.HtmlEncode(txtReason.Text.ToString().Trim()); //Replace new line with <BR> mailBody = mailBody.Replace("\r\n", "<BR>"); //Generate mail body omsg.Body = "Someone has requested a new Course Code be added to the " + LACESConstant.LACES_TEXT + " system. The details of the newly requested code are as follows:<br><br>"; omsg.Body += "Requested Code: " + Server.HtmlEncode(txtCodeType.Text.ToString()) + "<br>"; omsg.Body += "Reason: " + mailBody + "<br>"; omsg.Body += "Requester: " + provider.OrganizationName + "<br>"; omsg.Body += "Requester's Email: <a href='mailto:" + provider.ApplicantEmail + "'>" + provider.ApplicantEmail + "</a><br><br>"; omsg.Body += "If you wish to add this code to the " + LACESConstant.LACES_TEXT + " system, please <a href=\"http://" + Request.Url.Host.ToString() + "/admin/ManageCodeTypes.aspx\">manage the list of codes</a> in the administration system.<br><br>"; omsg.Body += "If you are going to reject the code, or wish to discuss the code further, please contact the course provider at their email address listed above."; //Set SMTP host from configuration smtpCl.Host = LACESUtilities.GetApplicationConstants(LACESConstant.SMTPSERVER).ToString(); smtpCl.Port = Convert.ToInt32(LACESUtilities.GetApplicationConstants(LACESConstant.SMTPPORT)); //Send mail if (ConfigurationManager.AppSettings["SendOutgoingEmail"].ToString() == "Y") { smtpCl.Send(omsg); } //Generate thank you message message = ""; lblMessage.Visible = true; lblMessage.Text = "Thank You! Your code request has been successfully submitted."; btnRequest.Visible = false; //After altering user if courseid is defind then send user to course detials page else send user to course list page if (Request.QueryString["CourseID"] != null) { long courseID = Convert.ToInt64(Request.QueryString["CourseID"]); //message += "location.replace(\"CourseDetails.aspx?CourseID=" + courseID + "\");"; message = "<META http-equiv=\"refresh\" content=\"5;URL=CourseDetails.aspx?CourseID=" + courseID + "\">"; lblMessage.Text = lblMessage.Text + "<BR>(You will be automatically redirected to course details page in 5 seconds.)"; } else { message = "<META http-equiv=\"refresh\" content=\"5;URL=CourseList.aspx\">"; lblMessage.Text = lblMessage.Text + "<BR>(You will be automatically redirected to course listing page in 5 seconds.)"; } } catch (Exception ex) { throw ex; } }