/// <summary> /// Send conformation email to customer <paramref name="email"/> /// </summary> /// <param name="email"></param> private void SendConfirmationEmail(string email) { EmailFactory factory = new EmailFactory(); MailAddress to = factory.GetMailAddress(email); MailAddress from = factory.GetMailAddress("fromAddress"); SmtpClient client = factory.GetSmtpClient(); MailMessage message = factory.GetMailMessage(to, from); message.Body = "Thank oyu for booking at us"; message.Subject = "Thanks for your purchase!"; EmailSender sender = factory.GetEmailSender(message, client, message.To.First(), message.From); sender.SendEmail(); }
public void SendMethod(UserRepository repo) { //здесь обработчик для события вернет список на отправку #region Raise Event Send send = new Send(); send.onEmailStartSending += PasswordApplication.Commands.EventDispatcher.send_onEmailStartSending; if (send.onEmailStartSending != null) { send.onEmailStartSending(send, new StartSendingEventArgs(repo)); } #endregion List <User> usersToSend = repo.UsersToSendlist; Queue <MailMessage> messagesQueue = new Queue <MailMessage>(); foreach (var user in usersToSend) { using (var message = EmailFactory.GetMailMessage(user.Email, user)) { messagesQueue.Enqueue(message); } } Parallel.ForEach(messagesQueue, (message) => { SendMailToUser(message); }); #region Raise PostSending Event send.onEmailPostSending += PasswordApplication.Commands.EventDispatcher.send_onEmailStartSending; if (send.onEmailStartSending != null) { send.onEmailStartSending(send, new StartSendingEventArgs(repo)); } #endregion }