using System.Net.Mail; var message = new MailMessage(); message.From = new MailAddress("[email protected]"); message.To.Add(new MailAddress("[email protected]")); message.Subject = "Hello, world!"; message.Body = "This is a test email message."; var smtpClient = new SmtpClient("smtp.example.com"); smtpClient.Send(message);
using System.IO; using System.Net.Mail; var message = new MailMessage(); message.From = new MailAddress("[email protected]"); message.To.Add(new MailAddress("[email protected]")); message.Subject = "Attachment Test"; message.Body = "Please see attachment."; // Add an attachment var attachment = new Attachment(@"C:\path\to\file.jpg"); message.Attachments.Add(attachment); var smtpClient = new SmtpClient("smtp.example.com"); smtpClient.Send(message);In these examples, the System.Net.Mail namespace is used.