none
I deliberately do not enter contact information in the fields in order to see what will be limited, RRS feed

  • Question

  • using ProjetDeStage2018.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Mail;
    using System.Web;
    using System.Web.Mvc;

    namespace ProjetDeStage2018.Controllers
    {
        public class HomeController : Controller
        {
            [Authorize]
            [HttpGet]
            public ActionResult Contact()
            {

                return View();
            }
            [HttpPost] 
            public ActionResult Contact(ContactModel contact)
            {
                var mail = new MailMessage();
                var loginInfo = new NetworkCredential("achrafmoulj@gmail.com","MLJAchraf9898");
                mail.From = new MailAddress(contact.Email);
                mail.To.Add(new MailAddress("achrafmoulj@gmail.com"));
                mail.Subject = contact.Objet;
                mail.IsBodyHtml = true;
                String body = "Nom de l'expéditeur : " + contact.Nom + "<br>" +
                              "Email de L'expéditeur : " + contact.Email + "<br>" +
                               "Objet : " + contact.Objet + "<br>" +
                               "Message : "  + contact.Message + "<b>";
                mail.Body = body;

                var smtpClient = new SmtpClient("smtp.gmail.com", 587);
                smtpClient.EnableSsl = true;
                smtpClient.Credentials = loginInfo;
                smtpClient.Send(mail);
                return RedirectToAction("Index");
            }
        }
    }

              ____________________________________________________________________________________

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web;

    namespace ProjetDeStage2018.Models
    {
        public class ContactModel
        {
            [Required]
            public String Nom { get; set; }
            [Required]
            public String Email { get; set; }
            [Required]
            public String Objet { get; set; }
            [Required]
            public String Message { get; set; }

        }
    }

                
    Monday, February 26, 2018 2:03 PM

All replies

  • Hi Achraf-help,

    Thank you for posting here.

    For your question is more related to MVC, you could post a new thread in MVC forum for suitable support.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions. 

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 27, 2018 5:57 AM