Advertisement
AyrA

C# E-mail send

Jun 30th, 2013
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. public static void SendMail(string from, string to, string subject, string message)
  2. {
  3.     MailMessage mMailMessage = new MailMessage();
  4.  
  5.     // Set the sender address of the mail message
  6.     mMailMessage.From = new MailAddress(from);
  7.     // Set the recepient address of the mail message
  8.     mMailMessage.To.Add(new MailAddress(to));
  9.  
  10.     // Set the subject of the mail message
  11.     mMailMessage.Subject = subject;
  12.     // Set the body of the mail message
  13.     mMailMessage.Body = message;
  14.  
  15.     // Set the format of the mail message body as HTML
  16.     mMailMessage.IsBodyHtml = false;
  17.     // Set the priority of the mail message to normal
  18.     mMailMessage.Priority = MailPriority.Normal;
  19.  
  20.     // Instantiate a new instance of SmtpClient
  21.     SmtpClient mSmtpClient = new SmtpClient();
  22.     // Send the mail message
  23.     mSmtpClient.Credentials = new NetworkCredential("USERNAME", "PASSWORD");
  24.     mSmtpClient.Host = "127.0.0.1";
  25.     mSmtpClient.Send(mMailMessage);
  26.     mMailMessage.Dispose();
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement