Search code examples
asp.net-mvcgmail

security of my gmail had to be changed in less secure apps - Asp.net MVC


I'm working on asp.net MVC web project and I want to send mail from a web page to my mail box. I followed this link to do that

http://www.c-sharpcorner.com/uploadfile/sourabh_mishra1/sending-an-e-mail-using-asp-net-mvc/

I used a gmail account to send and receive emails. but google asked me to turn on less secure apps and it warns me several times that I will lost my mail security after turns it on.

is it possible to tell me what should I do? Appreciate any help.

and also another question: I had to write my email's password in my code clearly

 smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new System.Net.NetworkCredential
            //here
            ("username", "password");// Enter seders User name and password  
            smtp.EnableSsl = true;
            smtp.Send(mail);
            return View("Index", _objModelMail);

does it matter in security of my web and my email?


Solution

  • send mail

    You may have used single-factor authentication (SFA) or two-factor authentication (2FA). You need to adjust settings for each. I think this link help you for smtp setting and gmail setting.

    password hard-coded

    Usually this isn't done as hard-coded. You can set password like this(dotnetnuke):

    smtp