示例#1
0
        public async Task SendAccountStatusAsync(bool accountActive, EmailContact Recipient, Uri BaseUrl)
        {
            string razorViewName = accountActive ? "Account Activated" : "Account Suspended";

            await SendRazorEmailAsync(null, Recipient, razorViewName, razorViewName.Replace(" ", ""),
                                      new _EmailLayout { Name = Recipient.Name, BaseUrl = BaseUrl });
        }
示例#2
0
        public async Task SendBookingInquiryAsync(EmailContact Sender, string subject, object vars)
        {
            EmailContact trust = await _Db.SystemSettings.OrderByDescending(o => o.Id)
                                 .Select(s => new EmailContact {
                Name = "Office", Address = s.EmailBookings
            }).FirstOrDefaultAsync();


            var message = await _ViewRender.RenderAsync("EmailRecieved", vars);

            await SendEmailAsync(Sender, trust, subject, message);

            List <EmailContact> CcRecipients = await _Db.NotificationChannels.Where(c => c.Name == "cc: Booking Enquiries")
                                               .Select(s => s.ChannelMemberships
                                                       .Select(s1 => new EmailContact
            {
                Name    = s1.Account.Name,
                Address = s1.Account.Email
            }).ToList()
                                                       ).FirstOrDefaultAsync();

            if (CcRecipients != null)
            {
                foreach (EmailContact recipient in CcRecipients)
                {
                    SendEmailAsync(Sender, recipient, $"FWD: {subject}", message);
                }
            }
        }
示例#3
0
        public async Task SendNewAccountEmailAsync(Models.PasswordReset token, ClaimsPrincipal adminAccount, Uri baseUrl)
        {
            var account   = token.Account;
            var recipient = new EmailContact {
                Address = account.Email, Name = account.Name
            };

            await SendRazorEmailAsync(null,
                                      recipient,
                                      "Account Created",
                                      "AccountCreated",
                                      new AccountCreated
            {
                Name      = account.Name,
                Recipient = recipient,
                CreatedBy = new EmailContact
                {
                    Name    = adminAccount.AccountName(),
                    Address = adminAccount.AccountEmail()
                },
                Token   = token.Token,
                BaseUrl = baseUrl
            }
                                      );
        }
示例#4
0
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        public async Task SendEmailAsync(EmailContact sender, EmailContact recipient, string subject, string message)
        {
            // IF: A sender is not specified then use the configuration value
            sender = sender ?? _EmailConfig.Sender.ToEmailContact();

            if (_env.IsDevelopment())
            {
                await SendViaSmtp(sender.ToMailboxAddress(), recipient.ToMailboxAddress(), subject, message);
            }
            else
            {
                await SendViaApi(sender, recipient, subject, message);
            }
        }
示例#5
0
        private async Task SendViaApi(EmailContact sender, EmailContact recipient, string subject, string message)
        {
            try
            {
                MessageService MailGun = new MessageService(_EmailConfig.Mailgun.ApiKey);
                var            Email   = new MessageBuilder()
                                         .AddToRecipient(new Recipient
                {
                    Email       = recipient.Address,
                    DisplayName = recipient.Name
                })
                                         .SetFromAddress(new Recipient
                {
                    Email       = sender.Address,
                    DisplayName = sender.Name
                })
                                         .SetReplyToAddress(new Recipient
                {
                    Email = _EmailConfig.Sender.ReplyTo ?? _EmailConfig.Sender.Address
                })
                                         .SetSubject(subject)
                                         .SetHtmlBody(message);

                var MailResult = await MailGun.SendMessageAsync(_EmailConfig.Mailgun.YourDomain, Email.GetMessage());

                _Logger.LogDebug("Email sent - Subject: {0} | Recipient: {1}<{2}>", subject, recipient.Name, recipient.Address);

                if (!MailResult.IsSuccessStatusCode)
                {
                    throw new Exception(MailResult.ReasonPhrase);
                }
            }
            catch (Exception ex)
            {
                _Logger.LogError("Error sending email - Subject: {0} | Recipient: {1}<{2}>: {3}", subject, recipient.Name, recipient.Address, ex.Message);
                throw ex;
            }
        }
示例#6
0
        public async Task SendRazorEmailAsync(EmailContact sender, EmailContact recipient, string subject, string viewName, object vars)
        {
            var message = await _ViewRender.RenderAsync(viewName, vars);

            await SendEmailAsync(sender, recipient, subject, message);
        }