Advertisement
ktostam450

C# Mail

Oct 29th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Net.Mail;
  4.  
  5. namespace WindowsApplication1
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.  
  14.         private void button1_Click(object sender, EventArgs e)
  15.         {
  16.             try
  17.             {
  18.                 MailMessage mail = new MailMessage();
  19.                 SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
  20.  
  21.                 mail.From = new MailAddress("[email protected]");
  22.                 mail.To.Add("to_address");
  23.                 mail.Subject = "Test Mail";
  24.                 mail.Body = "This is for testing SMTP mail from GMAIL";
  25.  
  26.                 SmtpServer.Port = 587;
  27.                 SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
  28.                 SmtpServer.EnableSsl = true;
  29.  
  30.                 SmtpServer.Send(mail);
  31.                 MessageBox.Show("mail Send");
  32.             }
  33.             catch (Exception ex)
  34.             {
  35.                 MessageBox.Show(ex.ToString());
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement