private async Task SendEmailAsync(NewJumpStart newJumpStart)
        {
            var emailRecipients = await GetRecipientsAsync(newJumpStart.Id);

            var emailInfo = await GetEmailInfoAsync(newJumpStart, emailRecipients);

            await _sendGridService.SendEmailAsync(emailInfo);

            foreach (var emailRecipient in emailRecipients)
            {
                emailRecipient.Status = EmailStatus.Sent;
            }

            await _dbContext.SaveChangesAsync();
        }
Esempio n. 2
0
        private async Task SendEmailAsync(JumpStart jumpStart, List <Article> articles)
        {
            var emails = await GetRecipientsAsync(jumpStart.Id);

            //var recipients = emails.Select(item => Tuple.Create(item.EmailAddress, (string?) null)).ToList();

            var emailInfo = await GetEmailInfoAsync(jumpStart, emails, articles);

            await _sendGridService.SendEmailAsync(emailInfo);

            foreach (var emailRecipient in emails)
            {
                emailRecipient.Status = EmailStatus.Sent;
            }

            await _dbContext.SaveChangesAsync();
        }
        public async Task SendEmailAsync_ShouldReturnCorrectResponse()
        {
            var configuration  = Configuration.InitConfiguration();
            var sendgridApiKey = configuration["Sendgrid:ApiKey"];
            var options        = new SendGridClientOptions();

            options.ApiKey = sendgridApiKey;
            var sendGridClient  = new SendGridClient(options.ApiKey);
            var sendGridService = new SendGridService(sendGridClient);

            var email    = GlobalConstants.ApplicationEmail;
            var name     = "Name";
            var subject  = "subject";
            var content  = "Some content";
            var response = await sendGridService.SendEmailAsync(email, name, subject, content);

            Assert.True(response.StatusCode.ToString() == "Accepted", ErrorMessage);
        }
Esempio n. 4
0
        public async Task SendAsync(int memoId)
        {
            var memo = await _dbContext.Memos.FirstOrDefaultAsync(item => item.Id == memoId);

            var recipients = await _dbContext.Emails
                             .Where(item => item.MemoId == memoId && item.Status == EmailStatus.ReadyToSend)
                             .ToListAsync();

            var emailInfo = await GetEmailInfoAsync(memo, recipients);

            await _sendGridService.SendEmailAsync(emailInfo);

            foreach (var recipient in recipients)
            {
                recipient.Status = EmailStatus.Sent;
            }

            await _dbContext.SaveChangesAsync();
        }
Esempio n. 5
0
        public async Task SendEmail(int tenantId, List <string> orders, decimal subTotal, decimal deliveryFee,
                                    decimal amount, decimal tax, DateTime deliveryDateTime, int userTimeZoneOffset, string paymentMethod,
                                    string?message, string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (user is null)
            {
                throw new Exception($"Cannot find the user: {userId}");
            }

            var tenant = await _meredithDbContext.Tenants
                         .Include(item => item.Owner)
                         .Include(item => item.Company)
                         .FirstOrDefaultAsync(item => item.Id == tenantId);

            if (tenant is null)
            {
                throw new Exception($"Cannot find the tenant: {tenantId}");
            }

            if (tenant.Company is null)
            {
                throw new Exception($"Tenant: {tenantId} is not connected to any company");
            }

            if (tenant.Owner is null)
            {
                throw new Exception($"Tenant: {tenantId} does not have an owner");
            }

            var recipients = new List <Tuple <string, string?> >
            {
                Tuple.Create <string, string?>(user.Email, user.FullName),
                Tuple.Create <string, string?>(tenant.Owner.Email, tenant.Owner.FullName)
            };

            var templateData = new
            {
                subject = $"your order with {tenant.Company.Name}",
                tenant  = new
                {
                    h2    = tenant.Name,
                    phone = tenant.Owner.PhoneNumber,
                    email = tenant.Owner.Email
                },
                orderProducts   = string.Join("<br />", orders),
                subTotal        = subTotal,
                deliveryFee     = deliveryFee,
                amount          = amount,
                tax             = tax,
                deliveryAddress = user.Address,
                name            = user.FullName,
                phone           = user.PhoneNumber,
                email           = user.Email,
                paymentMethod   = paymentMethod,
                deliveryTime    = deliveryDateTime.InZone(userTimeZoneOffset, "ddd, d MMM hh:mm"),
                message         = message ?? string.Empty,
                googleMaps      = user.GoogleLocation
            };

            var emailInfo = new EmailInfo(tenant.Company.Id, recipients)
            {
                TemplateData = templateData
            };

            await _sendGridService.SendEmailAsync(emailInfo);
        }