Send Mails in C#

This blog shows on how to send mail using .NET and C#.

MailMessage msg = new MailMessage();
    msg.From = new MailAddress("[email protected]", "email");

    msg.To.Add("[email protected]");
    msg.To.Add(new MailAddress("[email protected]", "email 2"));
    msg.Priority = MailPriority.High;

    msg.Subject = "test!";
    msg.Body ="Mail body here";
    msg.IsBodyHtml = true;

    msg.Attachments.Add(new Attachment("C:\\demo.txt"));

    SmtpClient client = new SmtpClient();
    client.Host = "smtp.gmail.com";
    client.Port = 578;
    client.EnableSsl = true;
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("[email protected]", "demo");
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.Send(msg);
Ebook Download
View all
Learn
View all