Ejemplo n.º 1
0
        bool INotificationReceiver.SendNotification(string subject, string message)
        {
            var mailData = new MailData()
            {
                From = _from,
                Recipients = new[] { _to },
                MessageBody = message,
                Subject = subject
            };

            try
            {
                if (string.IsNullOrEmpty(_pickupDirectory))
                {
                    _sendMail.Send(mailData, _mailSettings);
                }
                else
                {
                    _sendMail.Send(mailData, _pickupDirectory);
                }
            }
            catch (Exception ex)
            {
                throw new NotificationSentException("E-Mail-Notification konnte nicht gesendet werden.", ex);
            }

            return true;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        void ISendMail.Send(MailData mailData, string pickupDirectory)
        {
            _logger.Debug("Sending Mail '{@Mail}' via Pickup Directory '{@PickupDir}'", mailData, pickupDirectory);

            var smtpClient = new SmtpClient();
            smtpClient.PickupDirectoryLocation = pickupDirectory;
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;

            SendMails(mailData, smtpClient);
        }
Ejemplo n.º 4
0
        private static void SendMails(MailData mailData, SmtpClient smtpClient)
        {
            var message = new MailMessage()
            {
                From = new MailAddress(mailData.From),
                Subject = mailData.Subject,
                Body = mailData.MessageBody
            };

            foreach (var recipient in mailData.Recipients)
            {
                message.To.Add(recipient);
            }

            smtpClient.Send(message);
        }
Ejemplo n.º 5
0
 void ISendMail.Send(MailData mailData, AddressUsernamePassword mailSettings)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
 void ISendMail.Send(MailData mailData, string pickupDirectory)
 {
     throw new NotImplementedException();
 }