public MassEmailingActor() { Receive <BranchInfoAggregationActor.BranchInfosToPrint>(message => { var details = EmailDetails.Get(); foreach (var reposAndBranchInfo in message.ReposAndBranchInfos) { #if DEBUG string sendingTo = "*****@*****.**"; #else var committerEmail = reposAndBranchInfo.BranchInfo.CommitterEmail; var sendingTo = details.Exceptions.ContainsKey(committerEmail) ? details.Exceptions[committerEmail] : committerEmail; #endif var subject = GetSubject(reposAndBranchInfo); var content = GetContent(reposAndBranchInfo); try { SendEmail(details, sendingTo, subject, content); } catch (Exception e) { Logger.WriteLine($"Exception happened - {e.Message}"); Logger.SaveToFile(); } } }); }
public EmailingActor(IActorRef lastEmailedFileActor) { _lastEmailedFileActor = lastEmailedFileActor; Receive <PrinterActor.EmailContentToBeSent>(message => { #if DEBUG File.WriteAllText("..\\..\\Email.html", message.Content); #else var content = message.Content; var details = EmailDetails.Get(); foreach (var exception in details.Exceptions) { content = content.Replace(exception.Key, exception.Value); } var mail = new MailMessage(); var client = new SmtpClient(); client.Port = 587; client.Host = details.Host; mail.To.Add(new MailAddress(details.To)); mail.From = new MailAddress(details.From); mail.Subject = EmailSubject; mail.Body = content; mail.IsBodyHtml = true; client.EnableSsl = true; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(details.Username, details.Password); if (Constants.SendEmails) { client.Send(mail); } #endif _lastEmailedFileActor.Tell(new EmailedAtTime(DateTime.Now)); }); }