add ssl 1.2
[CPE_learningsite] / CPE / CPE.App / CPE.App.Api / Helpers / SendEmailHelper.cs
1 ´╗┐using System;
2 using System.Configuration;
3 using CPE.App.Web.Models;
4 using System.Net.Mail;
5 using CPE.App.Api.Models;
6 using Newtonsoft.Json;
7
8 namespace CPE.App.Api.Helpers
9 {
10     public class SendEmailHelper
11     {
12         public static bool SendCertificateEmail(PurchasedCourse course)
13         {
14             var courseEmail = course.Email;
15             var emailTest = ConfigurationManager.AppSettings["EmailTest"];
16             if (!string.IsNullOrWhiteSpace(emailTest))
17             {
18                 courseEmail = emailTest;
19             }
20
21             //elucidat cert email
22             var cDate = course.CertificateDate.Value.ToString("yyyyMMdd");
23             MailMessage mail = new MailMessage(ConfigurationManager.AppSettings["EmailSender"], courseEmail); 
24             SmtpClient client = new SmtpClient();
25             client.Port = 25;
26             client.DeliveryMethod = SmtpDeliveryMethod.Network;
27             client.UseDefaultCredentials = false;
28             client.Host = "localhost";
29             mail.Subject = ConfigurationManager.AppSettings["EmailSubject"];            
30             string mailBodyText = CPE.Utilities.Email.RenderEmail(course.ContentUrl, course.CertificateDate, course.Ticket);
31             mail.Body = mailBodyText;
32             mail.IsBodyHtml = true;
33             client.Send(mail);
34             return true;
35         }
36
37         public static bool SendBadReleaseEmail(ReleaseModel release)
38         {
39             MailMessage mail = new MailMessage("support@intesolv.com", ConfigurationManager.AppSettings["EmailReceiver"]); //TODO at DEPLOY: needs to be "sswebcast@cpeincmail.com" or better yet, move to config
40             SmtpClient client = new SmtpClient();
41             client.Port = 25;
42             client.DeliveryMethod = SmtpDeliveryMethod.Network;
43             client.UseDefaultCredentials = false;
44             client.Host = "localhost";
45             mail.Subject = "A new release wasn't properly updated.";
46             mail.Body = "A new release was processed improperly. Please verify the release description field is correct and create a new release." + Environment.NewLine + "Release code: " + release.ReleaseCode;
47             client.Send(mail);
48             return true;
49         }
50
51         public static bool SendProjectConfigFailEmail(string projectCode)
52         {
53             //not using. ignoring project_created webhooks
54             MailMessage mail = new MailMessage("support@intesolv.com", ConfigurationManager.AppSettings["EmailReceiver"]); 
55             SmtpClient client = new SmtpClient();
56             client.Port = 25;
57             client.DeliveryMethod = SmtpDeliveryMethod.Network;
58             client.UseDefaultCredentials = false;
59             client.Host = "localhost";
60             mail.Subject = "A new project was not configured properly.";
61             mail.Body = "A new project was created but the configuration of the project for tincan failed. " + Environment.NewLine + "Project Code: " + projectCode;
62             client.Send(mail);
63             return true;
64         }
65         public static bool SendCertificateGenerationFailedEmail(TinCanStatementModel statement)
66         {
67             MailMessage mail = new MailMessage("support@intesolv.com", ConfigurationManager.AppSettings["EmailReceiver"]); //TODO at DEPLOY change to "sswebcast@cpeincmail.com"
68             SmtpClient client = new SmtpClient();
69             client.Port = 25;
70             client.DeliveryMethod = SmtpDeliveryMethod.Network;
71             client.UseDefaultCredentials = false;
72             client.Host = "localhost";
73             mail.Subject = "Certificate Generation Failure";
74             mail.Body = "A user just passed an on-demand course and something went wrong processing their certificate. " + Environment.NewLine
75                 + "Please find the necessary information below for their Certificate of Completion. We recommend that you call InteSolv Support to update the Certificate Record. "
76                 + "Certificate information:" + Environment.NewLine 
77                 + JsonConvert.SerializeObject(statement, Formatting.Indented);
78             client.Send(mail);
79             return true;
80
81         }
82     }
83 }