Example #1
0
        public async Task <IActionResult> Send([FromBody] SendEmailInputModel sendEmailInputModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState.Values));
            }

            await _emailService.SendAsync(_emailConfiguration.To, sendEmailInputModel.Subject, sendEmailInputModel.Body);

            return(this.Ok());
        }
        public async Task <ActionResult> SendEmail(SendEmailInputModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Guid == null || !HasOrganiserPermission(model.Guid))
                {
                    return(NotFound());
                }

                var activity = await _repository.GuidToActivityAsync(model.Guid);

                var link = $"{this.Request.Scheme}://{this.Request.Host.Value}/EditAct/{nameof(EditActController.MainEdit)}?guid={model.Guid}";

                var body = "<p>You have been invited to {0}</p>  <p>{1}</p> <p>{2}</p> <a href={3}>{3}</a>";

                var message = new MailMessage();
                message.To.Add(new MailAddress(model.ToEmail));          // replace with valid value
                message.From    = new MailAddress(Secrets.emailSending); // replace with valid value
                message.Subject = "Your email subject";

                message.Body = string.Format(body, activity.Name,
                                             activity.Description,
                                             model.AdditionalTextMessage,
                                             link);

                message.IsBodyHtml = true;

                using (var smtp = new SmtpClient())
                {
                    var credential = new NetworkCredential
                    {
                        UserName = Secrets.emailSending,        // replace with valid value
                        Password = Secrets.emailSendingPassword // replace with valid value
                    };
                    smtp.Credentials = credential;
                    smtp.Host        = "smtp-mail.outlook.com";
                    smtp.Port        = 587;
                    smtp.EnableSsl   = true;
                    await smtp.SendMailAsync(message);

                    return(RedirectToAction("Sent"));
                }
            }
            return(View(model));
        }
Example #3
0
        public IActionResult Send([FromServices] IEmailSender emailSender, SendEmailInputModel inputModel)
        {
            MailAddress fromAddress = new MailAddress(inputModel.From);
            MailAddress toAddress   = new MailAddress(inputModel.To);

            MailMessage message = new MailMessage(fromAddress, toAddress)
            {
                Subject    = inputModel.Subject,
                Body       = inputModel.Body,
                IsBodyHtml = inputModel.IsHtml
            };

            emailSender.SendEmail(message);

            return(Ok(new SuccessResponse {
                Message = "Email successfully sent."
            }));
        }