示例#1
0
    /// <summary>
    /// Sending a mail after adding a course to the system
    /// </summary>
    /// <param name="course">Details of the course for sending email</param>
    /// <param name="stateProvince">State name</param>
    private void sendMail(Course course, string stateProvince)
    {
        //Provider provider = (Provider)Session[LACESConstant.SessionKeys.LOGEDIN_PROVIDER]; // get provider information from Session
        ApprovedProvider provider = (ApprovedProvider)Session[LACESConstant.SessionKeys.LOGEDIN_APPROVED_PROVIDER]; // get approved provider information from Session 
        string RefrenceURL = String.Empty;
        RefrenceURL = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.ToLower().LastIndexOf(LACESConstant.URLS.PROVIDER_BASE.ToLower())) + LACESConstant.URLS.ADMIN_BASE + "/" + LACESConstant.URLS.PENDING_COURSE;
        string courseDistance = string.Empty;
        if(course.DistanceEducation.Equals("Y"))
        {
            courseDistance = "Yes";
        }
        else
        {
            courseDistance = "No";
        }            
        if(course.StateProvince.Trim().Equals(string.Empty))
        {
            stateProvince = string.Empty;
        }

        StringBuilder EmailBody = new StringBuilder();
        EmailBody.Append("<table border='0' width='100%>");
        EmailBody.Append("<tr><td width='130'>&nbsp;</td><td>&nbsp;</td></tr>");
        EmailBody.Append("<tr><td colspan='2'>A new course has been added to the system by " + Server.HtmlEncode(provider.OrganizationName) + " and is <a href='" + RefrenceURL + "'>pending approval</a>. Please review the details of the course and either approve or reject the course.</td></tr>");
        EmailBody.Append("<tr><td colspan='2'><br/>The details of the new course are as follows:<br/></td></tr>");
        EmailBody.Append("<tr><td valign='top' width='130'>Course Title:</td><td>" + Server.HtmlEncode(course.Title) + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>Course Hyperlink:</td><td>" + Server.HtmlEncode(course.Hyperlink) + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>Start Date:</td><td>" + course.StartDate.ToString("MM/dd/yyyy") + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>End Date:</td><td>" + course.EndDate.ToString("MM/dd/yyyy") + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>Description:</td><td>" + Server.HtmlEncode(course.Description) + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>City:</td><td>" + Server.HtmlEncode(course.City) + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>State:</td><td>" + Server.HtmlEncode(stateProvince) + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>Distance Education:</td><td>" + courseDistance + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>Subjects:</td><td>" + course.Subjects + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>Health:</td><td>" + course.Healths + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>Hours:</td><td>" + course.Hours + "</td></tr>");
        EmailBody.Append("<tr><td valign='top'>Learning Outcomes:</td><td>" + Server.HtmlEncode(course.LearningOutcomes) + "</td></tr>");
        EmailBody.Append("<tr><td colspan='2'><br/>If you wish to add this course to the " + LACESConstant.LACES_TEXT + " system, please <a href='" + RefrenceURL + "'>manage the list of pending courses</a> in the administration system to approve it.<br/></td></tr>");
        EmailBody.Append("<tr><td colspan='2'><br/>If you are going to reject the course, or wish to discuss the course further, please contact the course provider <a href='mailto:" + provider.ApplicantEmail + "'>via email</a>.<br/></td></tr>");
        EmailBody.Append("</table>");
        string mailBody = EmailBody.ToString();


        try
        {
            SmtpClient smtpClient = new SmtpClient();
            //Get the SMTP server Address from SMTP Web.conf
            smtpClient.Host = LACESUtilities.GetApplicationConstants(LACESConstant.SMTPSERVER);
            //Get the SMTP post  25;
            smtpClient.Port = Convert.ToInt32(LACESUtilities.GetApplicationConstants(LACESConstant.SMTPPORT));

            MailMessage message = new MailMessage();

            message.From = new MailAddress(LACESUtilities.GetAdminFromEmail());
            
            //message.To.Add(LACESUtilities.GetAdminToEmail());
            //message.CC.Add(LACESUtilities.GetAdminCCEmail());

            //Get the email's TO from Web.conf
            message.To.Add(LACESUtilities.GetCourseNotificationMailTo());

            message.Subject = "New Course Added - Pending Approval";
            message.IsBodyHtml = true;
            message.Body = mailBody;    // Message Body
            if (ConfigurationManager.AppSettings["SendOutgoingEmail"].ToString() == "Y")
            {
                smtpClient.Send(message);   //Sending A Mail to Admin
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }