Tuesday 28 August 2018

MailCoding-Local


Add the Namespace

using System.Net;
using System.Net.Mail;


Add this code in your button click

           var smtp = new SmtpClient
        {
            Host = "smtp.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential("athirarajinesh@gmail.com", "password")//your mail id and password.
         
        };
                MailMessage m = new MailMessage();
                m.IsBodyHtml = true;
                m.To.Add("athi.litztech@gmail.com");//mail sending to. If you want to add multiple to address separate with comma.
                m.Bcc.Add("bcc.litztech@gmail.com");//attach a bcc copy
                m.CC.Add("cc.litztech@gmail.com");//attach a cc copy
                m.From = new MailAddress("athirarajinesh@gmail.com");//mail sending from
                m.Subject = "MailCoding-Local";
                m.Body = "Mail coding for sending mail in local host";
                m.IsBodyHtml = true;
                smtp.Send(m);

If you are using your mail for the first time then it will show an SMTP error.


You can solve this in your gmail settings.

To help keep Google Accounts through work, school, or other groups more secure, we block some less secure apps from using them. If you have this kind of account, you’ll see a "Password incorrect" error when trying to sign in. If so, you have two options:

  • Option 1: Install a more secure app that uses stronger security measures. All Google products, like Gmail, use the latest security measures.
  • Option 2: Change your settings to allow less secure apps into your account. We don't recommend this option because it can make it easier for someone to break into your account. If you want to allow access anyway, follow these steps:

  1. Go to the Less secure apps section of your Google Account.
  2. Turn on Allow less secure apps. If you don't see this setting, your administrator might have turned off less secure app account access.

Then you will be able to send the mail from your account and can be recieved.


No comments:

Post a Comment