public MailReceiver(string to, string from, AddressUsernamePassword mailSettings, ISendMail sendMail) { _to = to; _from = from; _sendMail = sendMail; _mailSettings = mailSettings; }
void ISendMail.Send(MailData mailData, AddressUsernamePassword mailSettings) { _logger.Debug("Sending Mail '{@Mail}' via SMTP '{@Settings}'", mailData, mailSettings); var hostAndPort = mailSettings.Address.Split(new[] { ':' }); var smtpClient = new SmtpClient(); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.Host = hostAndPort[0]; if (hostAndPort.Length > 1) { var port = int.Parse(hostAndPort[1]); smtpClient.Port = port; } if (mailSettings.UseDefaultCredentials) { smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials; } else { smtpClient.Credentials = new NetworkCredential(mailSettings.Username, mailSettings.Password); } SendMails(mailData, smtpClient); }
IEnumerable<INotificationReceiver> IConfigurationConverter.ConvertMessageReceivers(IEnumerable<MessageReceiver> receivers, AddressUsernamePassword mailSettings, string pickupDirectory, string fromEMailAddress) { return receivers.Select(receiver => { switch (receiver.Type) { case MessageReceiverType.EMail: if (string.IsNullOrEmpty(pickupDirectory)) { return _notificationReceiverFactory.CreateMailReceiver(receiver.Receiver, fromEMailAddress, _sendMail, mailSettings); } else { return _notificationReceiverFactory.CreateMailReceiver(receiver.Receiver, fromEMailAddress, _sendMail, pickupDirectory); } default: throw new NotImplementedException($"Der Empfänger-Typ {receiver.Type} ist bisher nicht implementiert!"); } }).ToArray(); }
INotificationReceiver INotificationReceiverFactory.CreateMailReceiver(string receiverMailAddress, string senderAddress, ISendMail sendMail, AddressUsernamePassword mailSettings) { return new MailReceiver(receiverMailAddress, senderAddress, mailSettings, sendMail); }
IEnumerable<INotificationReceiver> IConfigurationConverter.ConvertMessageReceivers(IEnumerable<MessageReceiver> receivers, AddressUsernamePassword mailSettings, string pickupDirectory, string fromEMailAddress) { throw new NotImplementedException(); }
void ISendMail.Send(MailData mailData, AddressUsernamePassword mailSettings) { throw new NotImplementedException(); }
INotificationReceiver INotificationReceiverFactory.CreateMailReceiver(string receiverMailAddress, string senderAddress, ISendMail sendMail, AddressUsernamePassword mailSettings) { ++CreateMailReceiverCalled; return CreateMailReceiver; }