예제 #1
0
        public async Task <IActionResult> Post([FromBody] ContactMailViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new InvalidCastException(ModelState.GetErrorModel());
                }

                var entity = Mapper.Map <ContactMail>(model);

                await _appMail.AddAsync(entity);

                return(Ok());
            }
            catch (InvalidCastException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (InvalidOperationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public ActionResult Contact(ContactMailViewModel vm)
        {
            if (ModelState.IsValid)
            {
                if (!User.Identity.IsAuthenticated && null == vm.Email)
                {
                    vm.Response = "Mail nie może być pusty.";
                    return(View(vm));
                }
                else
                {
                    try
                    {
                        MailMessage mailMessage = new MailMessage();
                        mailMessage.From = new MailAddress("*****@*****.**");//Email which you are getting

                        if (User.Identity.IsAuthenticated)
                        {
                            //from contact us page
                            mailMessage.To.Add("*****@*****.**");//Where mail will be sent
                            mailMessage.Subject = "[TicketSystem Contact page] Wiadomość od " + Task.Run(
                                async() => await UserManager.GetEmailAsync(
                                    User.Identity.GetUserId())).Result;
                        }
                        else
                        {
                            mailMessage.To.Add("*****@*****.**");//Where mail will be sent
                            mailMessage.Subject = "[TicketSystem Contact page] Wiadomość od " + vm.Email;
                        }

                        mailMessage.Body = vm.Message;
                        SmtpClient smtp = new SmtpClient
                        {
                            Host        = "poczta.o2.pl",
                            Port        = 587,
                            Credentials = new System.Net.NetworkCredential("*****@*****.**", "emailisk123"),
                            EnableSsl   = true
                        };

                        smtp.Send(mailMessage);

                        ModelState.Clear();
                        vm.IsSuccess = true;
                        vm.Response  = "Dziękujemy za wiadomość. Administrator wkrótce skontaktuje się z Tobą!";
                    }
                    catch (Exception ex)
                    {
                        ModelState.Clear();
                        vm.IsSuccess = false;

                        vm.Response = "Wystąpił problem. Spróbuj ponownie później...";
                    }
                }
            }

            return(View(vm));
        }
 public ActionResult Index(ContactMailViewModel model)
 {
     if (ModelState.IsValid)
     {
         var body = new StringBuilder();
         body.AppendLine("Ad & Soyad: " + model.Name);
         body.AppendLine("E-Mail Adresi: " + model.Email);
         body.AppendLine("Konu: " + model.Subject);
         body.AppendLine("Mesaj: " + model.Message);
         _contactService.MailSender(body.ToString());
         TempData["Message"] = "Mesajınız başarılı bir şekilde gönderildi.";
     }
     return(RedirectToAction("Index"));
 }
예제 #4
0
 public ActionResult Index(ContactMailViewModel model)
 {
     if (ModelState.IsValid)
     {
         var body = new StringBuilder();
         body.AppendLine("Ad & Soyad: " + model.Name);
         body.AppendLine("E-Mail Adresi: " + model.Email);
         body.AppendLine("Konu: " + model.Subject);
         body.AppendLine("Mesaj: " + model.Message);
         _contactService.MailSender(body.ToString());
         ViewBag.Success = true;
     }
     return(RedirectToAction("Index"));
 }
예제 #5
0
        public ActionResult ContactForm(FormCollection frm)
        {
            ContactMailViewModel model = new ContactMailViewModel {
                Name    = frm["name"],
                Email   = frm["email"],
                Phone   = frm["phone"],
                Comment = frm["comment"]
            };
            SmtpMailClient mail    = new SmtpMailClient();
            string         toEmail = ConfigurationManager.AppSettings["AdminEmail"];
            string         content = this.RenderRazorView("Mails/Contact", model);

            mail.PostMail(toEmail, "Iletisim Formu", content);
            return(View());
        }
예제 #6
0
        public async Task <IActionResult> SendMailAsync(ContactMailViewModel viewModel)
        {
            try
            {
                MimeMessage message = new MimeMessage();

                MailboxAddress from = new MailboxAddress("DevitoAnonymo Kontakt",
                                                         _configuration["from"]);
                message.From.Add(from);

                MailboxAddress to = new MailboxAddress("DevitoAnonymo Office",
                                                       _configuration["to"]);
                message.To.Add(to);

                message.Subject = "Nova Kontakt Poruka";

                BodyBuilder bodyBuilder = new BodyBuilder();
                bodyBuilder.HtmlBody = "<h1>Kontakt poruka</h1><br/>" +
                                       "<table>" +
                                       "<tbody>" +
                                       "<tr><th>Ime</th><td style='width: 200px'>" + viewModel.Name + "</td></tr>" +
                                       "<tr><th>Prezime</th><td style='width: 200px'>" + viewModel.LastName + "</td></tr>" +
                                       "<tr><th>Email</th><td style='width: 200px'>" + viewModel.Email + "</td></tr></tbody></table>" +
                                       "<h3>Poruka:</h3><p style='word-break: break-all;width: 300px;'>" + viewModel.Message + "</p>";

                message.Body = bodyBuilder.ToMessageBody();

                SmtpClient client = new SmtpClient();
                await client.ConnectAsync(_configuration["mailHost"], 465, true);

                await client.AuthenticateAsync(_configuration["from"], _configuration["appPass"]);

                await client.SendAsync(message);

                await client.DisconnectAsync(true);

                client.Dispose();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }



            _flashMessage.Info("Poruka uspešno poslata. ");
            return(RedirectToAction("Index", "Home"));
        }
예제 #7
0
        /// <summary>
        /// Sends a mail to the admin's emailaddress
        /// </summary>
        /// <param name="model">ContactMailViewModel</param>
        /// <returns>Returns actionresult Index</returns>
        public async Task <IActionResult> SendContactMailAsync(ContactMailViewModel model)
        {
            //Set up sendgrid API
            string         apiKey  = "";
            SendGridClient client  = new SendGridClient(apiKey);
            EmailAddress   from    = new EmailAddress(model.Email, model.FullName);
            EmailAddress   to      = new EmailAddress("*****@*****.**", "RicksWebWorld");
            string         subject = "New submission contactform WebWorld";

            //Set the content
            string          plainTextContent = model.Details;
            string          htmlContent      = model.Details;
            SendGridMessage msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);

            //Send the mail
            Response response = await client.SendEmailAsync(msg);

            return(RedirectToAction("Index", "Home"));
        }
예제 #8
0
        public IActionResult Index()
        {
            var viewModel = new ContactMailViewModel();

            return(View(viewModel));
        }