Mailmessage
You're referring to the MailMessage
class in.NET!
The MailMessage
class is a part of the System.Net.Mail namespace and is used to create and send email messages in.NET applications. It provides a way to create a message with a subject, body, and attachments, and then send it to one or more recipients using a mail server.
Here are some key properties and methods of the MailMessage
class:
Properties:
Subject
: The subject of the email message.Body
: The body of the email message.IsBodyHtml
: A boolean indicating whether the body of the message is in HTML format.From
: The email address of the sender.To
: The email address of the recipient(s).CC
: The email address of the carbon copy recipient(s).Bcc
: The email address of the blind carbon copy recipient(s).Attachments
: A collection of attachments to be sent with the message.
Methods:
Send()
: Sends the email message to the specified recipients using a mail server.SendAsync()
: Sends the email message to the specified recipients using a mail server asynchronously.Save()
: Saves the email message to a file.
Here's an example of how to use the MailMessage
class to send an email:
using System.Net.Mail;
// Create a new MailMessage object
MailMessage mail = new MailMessage();
// Set the sender and recipient
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
// Set the subject and body
mail.Subject = "Test Email";
mail.Body = "This is a test email message.";
// Add an attachment
mail.Attachments.Add(new Attachment("attachment.txt"));
// Send the email
SmtpClient client = new SmtpClient();
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.