Send Mail using Google Account (edit)
namespace ConsoleApp1 { using System; using System.IO; using System.Net.Mail; using System.Net.Mime; class Email { public static void Main(string[] args) { //You should enable application to access gmail account MailMessage m = new MailMessage(); SmtpClient sc = new SmtpClient(); try { m.From = new MailAddress("From@gmail.com", "From"); m.To.Add(new MailAddress("To@gmail.com", "To")); m.CC.Add(new MailAddress("CC@gmail.com", "Cc")); //Similarly BCC m.Subject = "Test1"; m.IsBodyHtml = true; m.Body = "This is a Test Mail"; FileStream fs = new FileStream("D:\\Downloads\\Test.pdf", FileMode.Open, FileAccess.Read); Attachment a = new Attachment(fs, "Test.pdf", MediaTypeNames.Application.Octet); m.Attachments.Add(a); string str = "<html><body><h1>Picture</h1><br/><img src =\"cid:image1\"></body></html>"; AlternateView av = AlternateView.CreateAlternateViewFromString(str, null, MediaTypeNames.Text.Html); LinkedResource lr = new LinkedResource("D:\\Downloads\\Test.jpg", MediaTypeNames.Image.Jpeg); lr.ContentId = "image1"; av.LinkedResources.Add(lr); m.AlternateViews.Add(av); sc.Host = "smtp.gmail.com"; sc.Port = 587; sc.Credentials = new System.Net.NetworkCredential("From@gmail.com", "YourPassword"); sc.EnableSsl = true; sc.Send(m); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } } } }
Signing in with 2-Step Verification
- How you sign in with 2-Step Verification
- Sign in faster with 2-Step Verification phone prompts
- Sign in using App Passwords
- Sign in with backup codes
- Sign in with your backup phone
- Sign in using QR codes
- Use your Android phone's built-in security key