using System.Net.Mail; // Create a new instance of the SmtpClient class SmtpClient smtpClient = new SmtpClient("smtp.example.com"); // Create a new MailMessage object MailMessage message = new MailMessage("[email protected]", "[email protected]"); // Set the subject and body of the email message message.Subject = "Test Email"; message.Body = "This is a test email message."; // Send the email message using the SmtpClient object smtpClient.Send(message);
using System.Net.Mail; using System.Net.Mime; // Create a new instance of the SmtpClient class SmtpClient smtpClient = new SmtpClient("smtp.example.com"); // Create a new MailMessage object MailMessage message = new MailMessage("[email protected]", "[email protected]"); // Set the subject and body of the email message message.Subject = "Test Email with Attachment"; message.Body = "This email contains an attachment."; // Add an attachment to the email message Attachment attachment = new Attachment(@"C:\example\attachment.txt", MediaTypeNames.Text.Plain); message.Attachments.Add(attachment); // Send the email message using the SmtpClient object smtpClient.Send(message);In this example, we're creating an instance of the SmtpClient class and specifying the SMTP server to use. We're then creating a new MailMessage object and setting the sender and recipient for the email message. We're also adding an attachment to the email message by creating an Attachment object and adding it to the message's Attachments collection. Finally, we're setting the subject and body of the email message and sending it using the SmtpClient object. Overall, the System.Net.Mail.SmtpClient package provides a simple and easy-to-use interface for sending email messages through a SMTP server using C#.