예제 #1
0
 private SMTPOutput SetResult(SMTPOutput outputResult, MailMessage mailMessage, SmtpClient smtp)
 {
     try
     {
         smtp.Send(mailMessage);
         outputResult.IsSuccess = true;
     }
     catch (Exception ex)
     {
         outputResult.Message   = ex.Message;
         outputResult.IsSuccess = false;
     }
     return(outputResult);
 }
예제 #2
0
        public virtual Task <IEmailOutput> SendAsync(IEmailInput emailInput)
        {
            SMTPInformation information  = CreateInformation();
            SMTPOutput      outputResult = new SMTPOutput();
            string          to           = emailInput.To;
            string          subject      = emailInput.Subject;
            string          body         = emailInput.Body;
            MailMessage     mailMessage  = GetMailMessage(information.From, to, subject, body);
            SmtpClient      smtp         = new SmtpClient(information.Host, information.Port)
            {
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(information.From, information.Password),
                EnableSsl             = true
            };

            SetResult(outputResult, mailMessage, smtp);
            return(Task.FromResult <IEmailOutput>(outputResult));
        }