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); }
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)); }