Guest User

Untitled

a guest
Aug 4th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net.Mail;
  6. using System.Net;
  7.  
  8. namespace GMAIL
  9. {
  10.     class Program
  11.     {
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             var fromAddress = new MailAddress("From Gmail", "From Name");
  16.             var toAddress = new MailAddress("To Address", "To Name");
  17.             const string fromPassword = "Gmail Password";
  18.             const string subject = "Testbesked";
  19.             const string body = "Testbesked";
  20.  
  21.             var smtp = new SmtpClient
  22.             {
  23.                 Host = "smtp.gmail.com",
  24.                 Port = 587,
  25.                 EnableSsl = true,
  26.                 DeliveryMethod = SmtpDeliveryMethod.Network,
  27.                 UseDefaultCredentials = false,
  28.                 Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  29.             };
  30.  
  31.             while (Console.ReadLine() != "exit")
  32.             {
  33.                 if (Console.ReadLine() == "send")
  34.                 {
  35.                     using (var message = new MailMessage(fromAddress, toAddress)
  36.                     {
  37.                         Subject = subject,
  38.                         Body = body
  39.                     })
  40.                     {
  41.                         smtp.Send(message);
  42.                         Console.WriteLine("Email successfully sent!");
  43.                     }
  44.                 }
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment