コード例 #1
0
        public async Task <ActionResult> DecryptMessage(EmailMessageViewModel message)
        {
            if (!message.MessageId.HasValue)
            {
                return(HttpNotFound());
            }

            var model = new ViewMessageIndexModel(_emailMessageService);
            await model.BuildAsync(message.MessageId.Value);

            if (!string.IsNullOrEmpty(message.EncryptionKey))
            {
                try
                {
                    model.Message.Message = await _emailMessageService.DecryptMessageAsync(
                        model.Message.Message,
                        message.EncryptionKey);
                }
                catch (CryptographicException)
                {
                    ModelState.AddModelError($"{nameof(message)}.{nameof(message.EncryptionKey)}", "Invalid encryption key!");
                }
            }

            return(View("ViewMessage", model));
        }
コード例 #2
0
        public async Task <ActionResult> Post(EmailMessageViewModel model)
        {
            var user = _context.Users.FirstOrDefault();

            if (user == null)
            {
                return(BadRequest("No user is registered."));
            }

            var requestIsValid = await _verificationService.IsCaptchaValid(model.Token);

            if (requestIsValid)
            {
                List <KeyValuePair <string, string> > variables = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>(Constants.EmailValues.Name, model.Name),
                    new KeyValuePair <string, string>(Constants.EmailValues.ReplyEmail, model.Email),
                    new KeyValuePair <string, string>(Constants.EmailValues.Message, model.Message)
                };
                var message = TemplateReader.GetTemplate(Constants.EmailTemplates.WebsiteMessageTemplate, variables);

                _emailService.Send(user.Email, "Blogcore Message", message, true);
                return(Ok(model));
            }
            return(BadRequest("Request did not pass validation"));
        }
コード例 #3
0
        public async Task <IActionResult> Index(EmailMessageViewModel emailMessageViewModel)
        {
            if (ModelState.IsValid)
            {
                var emailMessage = new EmailMessage
                {
                    SenderEmail   = SenderEmail,
                    ReceiverEmail = emailMessageViewModel.Email,
                    Subject       = emailMessageViewModel.Subject,
                    Body          = emailMessageViewModel.Message,
                    Status        = EmailMessageStatus.Pending
                };

                await _messageService.InsertAsync(emailMessage);

                //await _emailSenderService.Send(SenderEmail,
                //    emailMessageViewModel.Email,
                //    emailMessageViewModel.Subject,
                //    emailMessageViewModel.Message);

                return(View());
            }

            return(View(emailMessageViewModel));
        }
コード例 #4
0
        public HttpResponseMessage NlogEmailSender(EmailMessageViewModel emvm)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "Your fields are not valid"));
                }
                string key = ConfigurationManager.AppSettings["Sendgrid.Key"];

                EmailService service = new EmailService(key);

                EmailMessage msg = EmailMessage.CreateMessage(emvm.Email, emvm.Subject, emvm.Message);

                var fileName = FileToByteArrayConverter.GetFilePath("logs\\2018-05-18.log");
                var fileData = FileToByteArrayConverter.Convert(fileName);

                service.SendMail(msg, false, fileName, fileData);

                return(this.Request.CreateResponse(HttpStatusCode.OK, "Mail successfully sent"));
            }
            catch (Exception ex)
            {
                return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
コード例 #5
0
        public IActionResult SendBulkEmail([FromBody] EmailMessageViewModel emailMessageViewModel)
        {
            try
            {
                Emailing_EmailAddress from = new Emailing_EmailAddress();
                from.FullName     = "*****@*****.**";
                from.EmailAddress = _emailConfiguration.SmtpUsername;

                EmailMessage emailMessage = new EmailMessage();

                if (emailMessageViewModel.ToAddresses.Count == 0)
                {
                    List <Emailing_EmailAddress> emailAddresses = _context.MailingList.ToList();
                    emailMessage.ToAddresses = emailAddresses;
                }
                else
                {
                    emailMessage.ToAddresses = emailMessageViewModel.ToAddresses;
                }

                emailMessage.FromAddresses.Add(from);
                emailMessage.Subject = emailMessageViewModel.Subject;
                emailMessage.Content = emailMessageViewModel.Content;

                _emailService.Send(emailMessage);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
コード例 #6
0
        public ActionResult SendMessageIndex()
        {
            var model = new EmailMessageViewModel
            {
                ToUserName    = Request.QueryString.Get("t"),
                EncryptionKey = Extensions.GetUniqueKey(8)
            };

            return(View(model));
        }
コード例 #7
0
        public async Task <ActionResult> SendMessage(EmailMessageViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("SendMessageIndex", model));
            }

            var savedMessage = await _emailMessageService.SendMessageAsync(new EmailMessage
            {
                Message = model.Message,
                Subject = model.Subject
            }, model.EncryptionKey);

            return(await ViewMessage(savedMessage.MessageId));
        }
コード例 #8
0
        public ActionResult Compose(EmailMessageViewModel message)
        {
            var name = Config.ServiceBusQueueName;

            using (var qm = QueueFactory.GetQueue <EmailMessage>())
            {
                var email = new EmailMessage
                {
                    From = message.From,
                    To   = new List <string> {
                        message.To
                    },
                    EmailContent = message.EmailContent,
                    ContentType  = EmailContentType.TextHtml,
                    Subject      = message.Subject
                };

                qm.Enqueue(email);
            }
            TempData["message"] = "Message sent !!!";
            return(RedirectToRoute(new { action = "compose", controller = "email" }));
        }
コード例 #9
0
        public ActionResult NLog(EmailMessageViewModel em)
        {
            if (!ModelState.IsValid)
            {
                this.ModelState.AddModelError("", "Fields are not valid");
            }
            string key = ConfigurationManager.AppSettings["Sendgrid.Key"];

            SendGridEmailService service = new SendGridEmailService(key);

            EmailMessage msg = new EmailMessage
            {
                Recipient = em.Email,
                Body      = em.Message,
                Subject   = em.Subject
            };

            var fileName = FileToByteArrayConverter.GetFilePath("Logs\\2018-05-21.log");
            var fileData = FileToByteArrayConverter.Convert(fileName);

            service.SendMail(msg, false, fileName, fileData);

            return(RedirectToAction("SuccessPage", "Home"));
        }