/*
Developer: Tyler Allen
Date Created: 08/24/2016
---------------------------------------------------
*/
using System;
using System.Configuration;
using System.Net.Mail;
using CPE.App.Notify.Extensions;
using CPE.App.Notify.Models.Enums;
namespace CPE.App.Notify.Helpers {
public class EmailCertificateHelper {
///
/// Email the certificate results to the participant
///
/// Email recipient
/// Primary key of the meeting room
/// The date the meeting access was purchased
/// The ticket recieved when the meeting room was purchased
///
public static EmailCertificateResults SendWebcastCert(string to, int scoId, DateTime purchaseDate, string purchaseTicket) {
var subject = ConfigurationManager.AppSettings["WebcastCertEmailSubject"].Log(message: "Subject");
var certUrl = EmailRenderHelper.RenderCertificateLink(scoId, purchaseDate, purchaseTicket)
.Log(message: "RenderCertificateLink");
var body = EmailRenderHelper.RenderWebcastEmail(certUrl)
.Log(message: "Body");
return sendEmail(to, subject, body)
.Log();
}
///
/// Send a failure notice to the participant
///
/// Email recipient
///
public static EmailCertificateResults SendFailNotice(string to) {
var subject = ConfigurationManager.AppSettings["WebcastFailEmailSubject"].Log(message: "Subject");
var body = EmailRenderHelper.RenderFailEmail()
.Log(message: "Body");
return sendEmail(to, subject, body)
.Log();
}
///
/// Send email
///
/// Recipient
/// Subject
/// Body
///
private static EmailCertificateResults sendEmail(string to, string subject, string body) {
try {
var mail = new MailMessage(ConfigurationManager.AppSettings["WebcastEmailSender"], to) {
Subject = subject,
Body = body,
IsBodyHtml = true
};
var client = new SmtpClient {
Port = 25,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Host = ConfigurationManager.AppSettings["EmailServer"]
};
client.Send(mail);
} catch (Exception exception) {
exception.Log(LoggingLevels.Fatal);
return EmailCertificateResults.Fail;
}
return EmailCertificateResults.Success;
}
}
}