示例#1
0
        public virtual async Task <IEmailOutput> SendAsync(IEmailInput emailInput)
        {
            SendGridInformation sendGridInformation = CreateInformation();
            SendGridClient      client = new SendGridClient(sendGridInformation.ApiKey);
            SendGridMessage     msg    = new SendGridMessage()
            {
                From        = new EmailAddress(emailInput.FromEmail, name: emailInput.FromName),
                Subject     = emailInput.Subject,
                HtmlContent = emailInput.Body
            };

            msg.AddTo(new EmailAddress(emailInput.To));
            if (!string.IsNullOrEmpty(emailInput.Bcc))
            {
                msg.AddBcc(new EmailAddress(emailInput.Bcc));
            }

            Response result = await client.SendEmailAsync(msg);

            SendGridOutput sendGridOutput = new SendGridOutput
            {
                IsSuccess = result.StatusCode == System.Net.HttpStatusCode.Accepted
            };

            return(sendGridOutput);
        }
示例#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));
        }