public async Task <ActionResult> SendEmail([FromBody] Contact contact)
        {
            try
            {
                if (string.IsNullOrEmpty(contact.Email) || string.IsNullOrEmpty(contact.Message) || string.IsNullOrEmpty(contact.Name))
                {
                    _logger.LogDebug("Validation Error");
                    return(BadRequest());
                }

                bool response = await _sendEmailService.SendEmail(contact);

                if (response)
                {
                    return(Ok());
                }
                else
                {
                    _logger.LogError($"Error in {nameof(_sendEmailService)} service");
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #2
0
        public void SendNotifyMessage(string email, string courseDetails)
        {
            var subject = "Course start notification";
            var message = courseDetails;

            sendEmail.SendEmail(email, subject, message);
        }
 private async Task SendExceptionEmails(string message, string title)
 {
     foreach (var addr in targetEmails)
     {
         await email.SendEmail(addr, title,
                               $"<pre>{message}</pre>");
     }
 }
Example #4
0
 public async Task SendPasswordResetEmail(ApplicationUser?user, string subject,
                                          Func <string, string, string> bodyText)
 {
     if (user != null && await EmailMessageForUser(user, bodyText) is {} resetMessage)
     {
         await emailSender.SendEmail(user.UserName, subject,
                                     resetMessage);
     }
 }
Example #5
0
        public async Task <SendEmailResponse> Handle(SendEmailRequest request, CancellationToken cancellationToken)
        {
            bool response = await _sendEmailService.SendEmail(request);

            return(new SendEmailResponse()
            {
                Success = response
            });
        }
Example #6
0
 public async Task <IActionResult> SendEmailReport([FromBody] SendEmailParameterModel destinationEmail)
 {
     if (await _sendEmailServices.SendEmail(destinationEmail))
     {
         return(Ok(true));
     }
     else
     {
         return(Ok(false));
     }
 }
Example #7
0
        public void CreateAndSendAccessDeniedAlert(VaultAccessLog vaultAccessLog, string recipientAddress)
        {
            var senderAddress     = ConfigurationManager.AppSettings["SenderMailAddress"];
            var senderPassword    = ConfigurationManager.AppSettings["SenderMailPassword"];
            var emailSubject      = ConfigurationManager.AppSettings["EmailAlertSubject"];
            var alertTextTemplate = ConfigurationManager.AppSettings["EmailAlertTextTemplate"];

            var alertText = FillPlaceholders(alertTextTemplate, vaultAccessLog);

            _sendEmailService.SendEmail(senderAddress, senderPassword, recipientAddress, emailSubject, alertText);
        }
        public async Task DataProcess()
        {
            try
            {
                List <DayData> listDayData = await GetData();

                var xlsStream = await _xmlService.GetXml(listDayData);

                await _mailService.SendEmail(xlsStream);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return;
            }
        }
        public Task Consume(ConsumeContext <ISendEmailUserCommand> context)
        {
            var emailData = context.Message;
            var template  = EmailTemplateFactory.GetEmailTemplate(_emailMessageService, emailData);

            var message = new EmailMessageModel
            {
                To             = emailData.To,
                Subject        = template.Subject,
                Body           = template.Body,
                EmailMediaType = EmailMediaType.Html
            };

            _sendEmailService.SendEmail(message);

            return(Task.FromResult(context.Message));
        }
        public async Task <ProcessVerificationResult> SendExternalVerificationCode(ClaimsIdentity identity, string email)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentNullException(nameof(email));
            }

            var nameIdClaim    = identity.Claims.First(x => x.Type == Constants.ClaimTypes.ExternalProviderUserId);
            var provider       = nameIdClaim.Issuer;
            var providerUserId = nameIdClaim.Value;

            using (var db = _dbFactory())
            {
                var processresult = await ProcessVerification(email, provider, providerUserId, db, null, null);

                if (processresult != ProcessVerificationResult.Success)
                {
                    return(processresult);
                }

                var verification = await db.Verifications.SingleOrDefaultAsync(f => f.Provider == provider && f.ProviderId == providerUserId);

                if (verification == null)
                {
                    verification = new VerificationRow {
                        Provider = provider, ProviderId = providerUserId
                    };
                    db.Verifications.Add(verification);
                }

                verification.Created = DateTime.Now;
                verification.Code    = Guid.NewGuid().ToString().ToLowerInvariant().Replace("-", string.Empty);
                verification.Email   = email;
                await db.SaveChangesAsync();

                _log.Information(LogStrings.SendingVerifyCode, email, provider, providerUserId);
                await _emailService.SendEmail(email, Strings.VerifyMessageSubject, string.Format(Strings.VerifyMessageHtml, verification.Code));

                return(ProcessVerificationResult.Success);
            }
        }
Example #11
0
 public void Add()
 {
     Console.WriteLine("UserService Invoke Add Method");
     userRepository.Add();
     sendEmailService.SendEmail();
 }
        public ActionResult SendEmail(ContactViewModel model)
        {
            _emailService.SendEmail(model);

            return(RedirectToAction("Index", "Home"));
        }
Example #13
0
        public async Task <ActionResult> Modified(string formJSON, string oldPath)
        {
            string adminAuthenResult = await AdminAuthentication();

            if (!adminAuthenResult.Equals(string.Empty))
            {
                return(View(adminAuthenResult));
            }

            User   user  = GetUser();
            string email = user.Email;
            string token = user.Token;

            bool isCreate = oldPath.Equals(string.Empty);

            JObject jObject = JObject.Parse(formJSON);

            if (jObject.Count == 0)
            {
                return(Json(new { success = false, responseText = Messages.NO_COMPONENTS_IN_FORM }, JsonRequestBehavior.AllowGet));
            }

            string[] fields = { Keywords.TITLE, Keywords.PATH, Keywords.NAME, Keywords.ASSIGN, Keywords.START_DATE, Keywords.START_TIME, Keywords.EXPIRED_DATE, Keywords.EXPIRED_TIME };
            foreach (string field in fields)
            {
                if (jObject.GetValue(field) == null)
                {
                    return(Json(new { success = false, responseText = Messages.FILL(field) }, JsonRequestBehavior.AllowGet));
                }
            }

            string pathForm    = jObject.GetValue(Keywords.PATH).ToString();
            string assign      = jObject.GetValue(Keywords.ASSIGN).ToString();
            string startDate   = jObject.GetValue(Keywords.START_DATE).ToString();
            string expiredDate = jObject.GetValue(Keywords.EXPIRED_DATE).ToString();

            // Compare date, start > expired
            try {
                DateTime date1 = DateTime.Parse(startDate);
                DateTime date2 = DateTime.Parse(expiredDate);
                if (DateTime.Compare(date1, date2) >= 0)
                {
                    return(Json(new { success = false, responseText = Messages.DATE_PICK_ERROR }, JsonRequestBehavior.AllowGet));
                }
            } catch (FormatException) {
                return(Json(new { success = false, responseText = Messages.FORMAT_DATE_ERROR }, JsonRequestBehavior.AllowGet));
            }

            // Get start and expired date time to save in database
            string start   = startDate + " " + jObject.GetValue(Keywords.START_TIME).ToString();
            string expired = expiredDate + " " + jObject.GetValue(Keywords.EXPIRED_TIME).ToString();

            // Send to form.io server and save to database
            string res = await _formService.BuildForm(token, formJSON, isCreate?string.Empty : oldPath);

            string sendResult = string.Empty;

            if (isCreate)
            {
                bool isInserted = _formControlService.Insert(new FormControl(pathForm, email, assign, start, expired));
                if (!isInserted)
                {
                    return(Json(new { success = false, responseText = Messages.DATABASE_ERROR }, JsonRequestBehavior.AllowGet));
                }

                // Send email
                sendResult = await _sendEmailService.SendEmail(token, assign, jObject.GetValue(Keywords.TITLE).ToString());

                if (string.Empty.Equals(sendResult))
                {
                    sendResult = Messages.SEND_MAIL_SUCCESSFUL;
                }
            }
            else
            {
                long rowAffected = await _formControlService.Update(new FormControl(pathForm, email, assign, start, expired), oldPath);

                if (rowAffected < 1)
                {
                    return(Json(new { success = false, responseText = Messages.DATABASE_ERROR }, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(new { success = true, responseText = res, sendEmail = sendResult }, JsonRequestBehavior.AllowGet));
        }
Example #14
0
 public Task Run(string body)
 {
     return(_sendEmailServiceAcl.SendEmail(body));
 }