System.net.mail.mailmessage

A popular topic!

System.Net.Mail.MailMessage is a.NET class used to create and send email messages using the Simple Mail Transfer Protocol (SMTP). It is part of the.NET Framework and is commonly used in ASP.NET and Windows Forms applications.

Here are some key properties and methods of the MailMessage class:

Properties:

Methods:

Example usage:

Here's an example of how to create and send an email message using the MailMessage class:

using System.Net.Mail;

// Create a new MailMessage object
MailMessage mail = new MailMessage();

// Set the sender's email address
mail.From = new MailAddress("[email protected]");

// Set the recipient's email address
mail.To.Add("[email protected]");

// Set the subject of the email message
mail.Subject = "Test email";

// Set the body of the email message
mail.Body = "This is a test email message.";

// Set the priority of the email message
mail.Priority = MailPriority.Normal;

// Create a new SmtpClient object
SmtpClient client = new SmtpClient();

// Set the SMTP server's address and port
client.Host = "smtp.example.com";
client.Port = 587;

// Send the email message
client.Send(mail);

Note that this is just a basic example, and you may need to add additional configuration and error handling depending on your specific requirements.