Wednesday, September 7, 2016

C# gmail smtp server mailing

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace email_try
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential("vadivelan.udayakumar@gmail.com", "password"),
                EnableSsl = true
               
        };

            client.Send("vadivelan.udayakumar@gmail.com", "vadivelan.recepient@gmail.com", "test", "testbody");
            Console.WriteLine("Sent");
            Console.ReadLine();

        }
    }
}



Then goto:

https://www.google.com/settings/security/lesssecureapps

and turn it on for the sender account.







No comments:

Post a Comment