Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Commit

Permalink
Implemented the NotificationEmailSender.
Browse files Browse the repository at this point in the history
  • Loading branch information
bofirial committed Jun 11, 2017
1 parent 08397c3 commit 62addaf
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions Melody49Notifier/Notification/NotificationEmailSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,49 @@
using System.Threading.Tasks;
using Melody49Notifier.Models;
using Microsoft.Azure.WebJobs.Host;
using System.Net.Mail;
using System.Net;
using System.IO;

namespace Melody49Notifier.Notification
{
public class NotificationEmailSender : INotificationEmailSender
{
public NotificationEmailSender(TraceWriter log)
private readonly INotificationEmailGenerator notificationEmailGenerator;

public NotificationEmailSender(TraceWriter log, INotificationEmailGenerator notificationEmailGenerator)
{
Log = log;
this.notificationEmailGenerator = notificationEmailGenerator;
}

public TraceWriter Log { get; }

public void SendNotificationEmail(TheaterSchedule currentTheaterSchedule)
{
throw new NotImplementedException();
MailMessage message = new MailMessage()
{
From = new MailAddress(Environment.GetEnvironmentVariable("FromEmailAddress"), "Melody 49 Drive-In"),
Subject = "New Showings at the Melody 49 Drive-In",
Body = notificationEmailGenerator.CreateFromTemplate(currentTheaterSchedule),
IsBodyHtml = true
};

string[] emailAddresses = Environment.GetEnvironmentVariable("ToEmailAddresses").Split(',');

foreach (string emailAddress in emailAddresses)
{
message.To.Add(emailAddress);
}

SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587)
{
EnableSsl = true,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(Environment.GetEnvironmentVariable("SMTPUserName"), Environment.GetEnvironmentVariable("SMTPPassword"), "")
};

smtpClient.Send(message);
}
}
}

0 comments on commit 62addaf

Please sign in to comment.