using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Mail; using System.Net; namespace SendEmail { class Program { static void Main(string[] args) { Email(); } static void Email() { var fromAddress = new MailAddress("", ""); var toAddress = new MailAddress("", ""); const string fromPassword = ""; const string subject = ""; const string body = ""; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, Credentials = new NetworkCredential(fromAddress.Address, fromPassword), Timeout = 20000 }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body, }) { smtp.Send(message); } } } }
using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body, }) { Attachment a = new Attachment("filename.txt"); message.Attachments.Add(a); smtp.Send(message); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)