SHARE
TWEET

Untitled

a guest Jan 20th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Add Reference:
  2.   using System.Net;
  3.   using System.Net.Mail;
  4.  
  5. Code:
  6.  
  7.       string to = "ReceiverName@gmail.com";
  8.       string from = "SenderName@gmail.com";
  9.       MailMessage message = new MailMessage(from, to);
  10.       message.Subject = "Using the new SMTP client.";
  11.       message.Body = @"Using this new feature, you can send an email message from an application very easily.";
  12.       message.Attachments.Add(new Attachment("c:\\test.txt"));
  13.       SmtpClient client = new SmtpClient(server, 587);
  14.       client.EnableSsl = true;
  15.       //client.UseDefaultCredentials = true;
  16.       client.Credentials = new NetworkCredential("UserName", "Password");
  17.  
  18.       try
  19.       {
  20.         client.Send(message);
  21.       }
  22.       catch (Exception ex)
  23.       {
  24.         Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString());
  25.       }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top