Send Email using smtpClient

We can send the email using the smtpclient.
The following code will explain how to send the email using smtpclient

Following namespace is used to send email
using System.Net.Mail;

MailMessage MyMailMessage = new MailMessage();
MyMailMessage.Subject = "My Subject";
MyMailMessage.To.Add("To Address ");
MyMailMessage.From = new System.Net.Mail.MailAddress("My From AddressP".Replace("[",
"<").Replace("]", ">"));
Message.Body = " Email Body Content";

SmtpClient MySmtpClient = new SmtpClient("MailServer", 25);

Code Explanation

1. Create the instance of "MailMessage".
2. Fill the properties.
3. Create instance of SmtpClient for the mail server.
4. Send the "MailMessage" through "SmtpClient".



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: