Ejemplo n.º 1
0
        public async Task <IActionResult> SendToReview(Guid transactionId)
        {
            Guid userId = this.HttpContext.User.GetId() !.Value;

            Transaction transaction = await this.dbContext.Transactions
                                      .SingleAsync(t => t.Id == transactionId);

            if (transaction.Status != Transaction.Statuses.Initialized || userId != transaction.InitiatorId)
            {
                return(this.BadRequest());
            }

            transaction.Status = Transaction.Statuses.Reviewed;

            await this.dbContext.SaveChangesAsync();

            await mailSender.SendEmail(
                "NewTransaction",
                new NewTransactionContext(transaction.Recipient.Email, "New transaction"));


            return(this.RedirectToAction("Index", new
            {
                id = transaction.Id,
            }));
        }
        // a helper method to test the sending by the given email proviser
        // using a hard-coded email details
        public static async Task <bool> TestSendEmail(IMailSender emailSender)
        {
            var isSent = await emailSender.SendEmail(EmailDetails, telelemtry : null);

            if (isSent)
            {
                return(true);
            }

            //retry in case there is a temporary down time of the provider
            return(await emailSender.SendEmail(EmailDetails, telelemtry : null));
        }
        public async Task Execute(long bulkId, List <string> recipients, string?replyTo,
                                  CancellationToken cancellationToken)
        {
            var bulkInfo = await database.SentBulkEmails.FindAsync(new object[] { bulkId }, cancellationToken);

            if (bulkInfo == null)
            {
                logger.LogError("Can't send bulk email {BulkId} to recipients, can't find sent data", bulkId);
                return;
            }

            cancellationToken.ThrowIfCancellationRequested();

            // Once we start sending we would need a job database write if we need to cancel, so for now we don't
            // allow canceling after starting
            foreach (var recipient in recipients)
            {
                await mailSender.SendEmail(new MailRequest(recipient, bulkInfo.Title)
                {
                    ReplyTo       = replyTo,
                    HtmlBody      = bulkInfo.HtmlBody,
                    PlainTextBody = bulkInfo.PlainBody,
                }, CancellationToken.None);
            }
        }
Ejemplo n.º 4
0
        public KeyValuePair <DateTime, bool>[] GetInfoForNext15Days()
        {
            var targetDates = GetDatesForVerification();
            var result      = new KeyValuePair <DateTime, bool> [targetDates.Length];

            for (var i = 0; i < targetDates.Length; i++)
            {
                var date = targetDates[i];
                try
                {
                    var data = _duwStorage.ReadDataByDate(date);
                    result[i] = new KeyValuePair <DateTime, bool>(date, HasFreeSlots(data));
                }
                catch (Exception ex)
                {
                    _mailSender.SendEmail(new Message
                    {
                        Body      = $"Exception occured during getting info for {date}. Exception: {ex}",
                        Recepient = "*****@*****.**",
                        Sender    = "*****@*****.**",
                        Subject   = $"EXCEPTION OCCURED {DateTime.Now.ToString("g")}"
                    });
                    break;
                }
            }
            return(result);
        }
        public async Task <IActionResult> SendTestMail([FromBody][Required] EmailTestRequestForm request)
        {
            if (!mailSender.Configured)
            {
                return(BadRequest("Email is not configured"));
            }

            logger.LogInformation("Test email sent by {Email} to {Recipient}", HttpContext.AuthenticatedUser() !.Email,
                                  request.Recipient);

            try
            {
                await mailSender.SendEmail(new MailRequest(request.Recipient, "Test Email from ThriveDevCenter")
                {
                    PlainTextBody =
                        "This is a test email from ThriveDevCenter.\n If you received this, then things are working.",
                    HtmlBody =
                        "<p>This is a test email from ThriveDevCenter.</p>" +
                        "<p>If you received this, then things are working.</p>",
                }, CancellationToken.None);
            }
            catch (Exception e)
            {
                logger.LogError("Error when sending test email: {@E}", e);
                return(Problem("Error sending test mail. See server logs for more details."));
            }

            return(Ok());
        }
Ejemplo n.º 6
0
        public static async Task <bool> ProcessMessage(CloudQueueMessage queueMsg,
                                                       IMailSender emailVendor,
                                                       CancellationToken cancellationToken)
        {
            const int maxDequeue = 5;

            try
            {
                // check whether a message was pulled out and returned to the queue five times
                if (queueMsg.DequeueCount >= maxDequeue)
                {
                    // if that's that case, report and return
                    telemetry.TrackTrace($"Skipping message after {maxDequeue} dequeues. " +
                                         $"Message: {queueMsg?.AsString}");

                    // return 'true' in order for the message will be deleted by the Worker Role
                    return(true);
                }

                var xSerilizer   = new XmlSerializer(typeof(EmailDetails));
                var emailDetails = (EmailDetails)xSerilizer.Deserialize(new StringReader(queueMsg.AsString));
                return(await emailVendor.SendEmail(emailDetails, telemetry, cancellationToken));
            } catch (Exception e)
            {
                //should not happen as there is a catch inside
                telemetry.TrackException(e,
                                         new Dictionary <string, string> {
                    [emailVendor.GetType().Name] = queueMsg?.AsString
                });

                return(false);
            }
        }
Ejemplo n.º 7
0
        private string SendEmail(int id)
        {
            string userEmail   = _userProvider.GetUserEmailById(id);
            string emailBody   = GetUserReport(id);
            var    emailStatus = _mailSender.SendEmail(userEmail, emailBody);

            return(emailStatus);
        }
        private void EmailWorksheetWithGivenQuestionsAsync(string emailAddress, List <IQuestion> questions)
        {
            var pdfBuilder = new BasicPdfBuilder(questions, "title", "instructions");
            var streams    = pdfBuilder.CreatePdfsAsMemoryStreams();

            mailSender.SendEmail(emailAddress, streams);

            foreach (var stream in streams)
            {
                stream.Dispose();
            }
        }
Ejemplo n.º 9
0
        public async Task ResetPassword(ResetPasswordCommand command)
        {
            var user = await _identityRepository.GetByMailAsync(command.Email);

            if (user is null)
            {
                throw new IdentityExceptions("User with this email not found");
            }

            var randomPassword = StringExtension.RandomString(8);

            var salt = _encrypter.GetSalt(randomPassword);
            var hash = _encrypter.GetHash(randomPassword, salt);

            user.SetPassword(user.Password, user.Password);
            await _identityRepository.EditPasswordAsync(user);

            await _mailSender.SendEmail(command.Email, randomPassword);
        }
Ejemplo n.º 10
0
 public void ResetPassword(User user)
 {
     if (user == null)
     {
         throw new ArgumentException("User is null", "user");
     }
     try
     {
         _userRepository.StartTransaction();
         var newPassword = _passwordGenerator.GenerateRandomPassword();
         user.PasswordHash = _passwordCryptography.GenerateHash(newPassword);
         _userRepository.UpdateUser(user);
         _userRepository.Commit();
         _mailSender.SendEmail(user.Email, CreateNewPasswordBody(newPassword), "New Password");
     }
     catch (Exception e)
     {
         _userRepository.Rollback();
         _log.LogError("Error in password reset", e);
     }
 }
Ejemplo n.º 11
0
        public override async Task ReceiveMessage(IModel model, TModel message, BasicDeliverEventArgs e, ILogger logger)
        {
            try
            {
                //Generate mailModel
                var mailModel = _mailModelFactory.Create(message);

                //Send confirmation email
                await _mailSender.SendEmail(mailModel);

                //Log this action
                _logger.LogInfo("MailSenderMassTransitConsumer.Consume",
                                $"Mail of type {model.ToString()} sent to mailbox: {mailModel.To}");
            }
            catch (Exception ex)
            {
                _logger.LogError("ConfirmMailModelConsumer.Consume", $"Some error occurred", new
                {
                    Model     = model,
                    Exception = ex
                });
            }
        }
Ejemplo n.º 12
0
 public void Send(string content)
 {
     _mailSender.SendEmail(new MailMessage(_options.Subject, content, _options.Tos.ToList()));
 }
 public void Process()
 {
     _mailSender.SendEmail(ConfigurationManager.AppSettings["surveySubject"]);
 }
Ejemplo n.º 14
0
        public async Task Execute(MailRequest mailRequest, CancellationToken cancellationToken)
        {
            await mailSender.SendEmail(mailRequest, cancellationToken);

            logger.LogInformation("Sent queued email to {Recipient}", mailRequest.Recipient);
        }