Send Email In C#

public void Mail


// Creating a new mail message. The sender and receiver are
// indicated as and
MailMessage mail = new MailMessage();

// Creating a new SMTP Client. The server URL/IP is indicated as
// sendServer.Text (that is the text box with the data).
SmtpClient SmtpServer = new SmtpClient(“”);

mail.From = new MailAddress(“”);//Set The Email Address Of the Sender.
mail.To.Add(“”);//Set The Email Address Of Reciever.
mail.Subject = “Test Mail”;//Subject Of The Mail.
mail.Body = “This is for testing SMTP mail from GMAIL”;//It Is the Main Body Of The Email. Also Append HTMl Code.  

 // Some servers require a specific port to connect
SmtpServer.Port = 587;

 // To be able to send the message, it is necessary to provide the
// credentials on the server. The username and the password is to give.                
SmtpServer.Credentials = new System.Net.NetworkCredential(“”, “password”);
SmtpServer.EnableSsl = true;

// Send the Mail.
MessageBox.Show(“Mail Send”);

catch (Exception ex)




Posts Tagged with…

Write a Comment

Your email address will not be published. Required fields are marked *