using System.Net.Mail; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential("[email protected]", "yourpassword"); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress("[email protected]"); mailMessage.To.Add("[email protected]"); mailMessage.Subject = "Test email"; mailMessage.Body = "Hello, this is a test email."; client.Send(mailMessage);
using System.Net.Mail; using System.Net.Mime; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential("[email protected]", "yourpassword"); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress("[email protected]"); mailMessage.To.Add("[email protected]"); mailMessage.Subject = "Test email with attachment"; mailMessage.Body = "Hello, this is a test email with an attachment."; Attachment attachment = new Attachment(@"C:\path\to\file.pdf", MediaTypeNames.Application.Pdf); mailMessage.Attachments.Add(attachment); client.Send(mailMessage);This example sends an email with an attachment. The attachment is specified as a file path, and the media type is `application/pdf`. The package library for these examples is the .NET Framework class library, which includes the `System.Net.Mail` namespace.