Send Email c#

Here’s how to send some email in c#

using System.Net.Mail;
using System.Net.Mime;
using System.Net;

///place in a sub-routine or button
try
{
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient("smtp.example.com");
MailMessage message = new MailMessage("[email protected]", "[email protected]"); // , 
message.Body = "test e-mail"
message.Subject = "Test Subject from C#"
client.Port = System.Convert.ToInt32("25");
client.Send(message);
MessageBox.Show("Email Sent Successfully");
}
catch (Exception ex)
{
    MessageBox.Show("Cannot send message: " + ex.Message);
}

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.