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