Ejemplo n.º 1
0
        public MailerResult Send(MailPigEmail mail)
        {
            MailerResult result = ValidateMail(mail);
            if (!result.IsValid)
            {
                return result;
            }

            MailMessage message = Compose(mail);

            return SendInternal(message, mail);
        }
Ejemplo n.º 2
0
 private MailerResult SendInternal(MailMessage message, MailPigEmail mail)
 {
     try
     {
         this._mailer.Send(message);
         mail.SendSuceeded();
         return new MailerResult();
     }
     catch (Exception ex)
     {
         return new MailerResult(MailerResultStatusEnum.Exception, ex.Message, ex);
     }
 }
Ejemplo n.º 3
0
        private MailMessage Compose(MailPigEmail mail)
        {
            MailMessage message = new MailMessage();

            message.From = new MailAddress(mail.Sender);
            //message.Sender = new MailAddress(mail.Sender);

            message.To.Add(new MailAddress(mail.Recipient));

            message.Subject = mail.Subject;
            message.Body = mail.Body;
            message.IsBodyHtml = true;

            return message;
        }
Ejemplo n.º 4
0
        private MailerResult ValidateMail(MailPigEmail mail)
        {
            MailerResult result = new MailerResult();

            if (!_mailRegex.IsMatch(mail.Sender))
            {
                result.Status = (result.Status & ~MailerResultStatusEnum.Succeeded) |
                                MailerResultStatusEnum.InvalidSender;
                result.Message += string.Format("Invalid sender e-mail {0}", mail.Sender) + Environment.NewLine;
            }

            if (!_mailRegex.IsMatch(mail.Recipient))
            {
                result.Status = (result.Status & ~MailerResultStatusEnum.Succeeded) |
                                MailerResultStatusEnum.InvalidRecipient;
                result.Message += string.Format("Invalid recipient e-mail {0}", mail.Recipient) + Environment.NewLine;
            }

            return result;
        }