コード例 #1
0
        public async Task SendEmail(MailModel mailModel)
        {
            try
            {
                var email = new FluentEmail.Core.Email(mailModel.From)
                            .To(mailModel.To)
                            .Subject(mailModel.Subject);
                email.Renderer = new RazorRenderer();

                if (mailModel.TemplateFile != null)
                {
                    email.UsingTemplateFromFile <ViewModel>(mailModel.TemplateFile, mailModel.ViewModel);
                }
                else
                {
                    email.UsingTemplate <ViewModel>(mailModel.Template, mailModel.ViewModel);
                }

                await _smtpSender.SendAsync(email);
            }
            catch (SmtpFailedRecipientException ex)
            {
                _logger.LogError("SmtpMailSender.SendEmail", "SmtpFailedRecipientException occurred while sending mail", new
                {
                    MailModel    = mailModel,
                    SmtpSettings = _smtpSettings,
                    Exception    = ex
                });
            }
            catch (Exception ex)
            {
                _logger.LogError("SmtpMailSender.SendEmail", "Exception occurred while sending mail", new
                {
                    MailModel    = mailModel,
                    SmtpSettings = _smtpSettings,
                    Exception    = ex
                });

                throw;
            }
        }
コード例 #2
0
        public override bool SendMessage(SendMessage message)
        {
            var smtpSender = new SmtpSender(new SmtpClient()
            {
                EnableSsl             = Auth.EnableSSL,
                UseDefaultCredentials = false,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                Port        = Auth.Port,
                Host        = Auth.Host,
                Credentials = new NetworkCredential(Auth.From, Auth.Password),
            });

            var email = Email.From(Auth.From, Auth.FromName)
                        .Subject(message.Title)
                        .Body(message.Data ?? "")
                        .To(Auth.To);

            smtpSender.SendAsync(email);

            return(true);
        }
コード例 #3
0
ファイル: MailtrapSender.cs プロジェクト: zs2hx/FluentEmail
        public async Task <SendResponse> SendAsync(IFluentEmail email, CancellationToken?token = null)
        {
            var smtpSender = new SmtpSender(_smtpClient);

            return(await smtpSender.SendAsync(email, token));
        }