| In C#, MailMessage is a class within the `System.Net.Mail` namespace used to represent an email message. It allows you to set properties like the sender, recipient, subject, body, attachments, and other email-related attributes. You can then use a `SmtpClient` object to send the message via a specified SMTP server. SmtpMail is a deprecated class in C# for sending emails using the Simple Mail Transfer Protocol (SMTP). It's been replaced by the `System.Net.Mail` namespace, which provides more robust and feature-rich classes like SmtpClient for sending emails, MailMessage for composing the email content, and `Attachment` for adding attachments. While `SmtpMail` is still available for legacy code, it's highly recommended to use the `System.Net.Mail` namespace for modern email sending needs.
A code snippet,posted on the dotnet newsgroup,about how to send email using C#. <%@Import <mailto:%@Import> namespace="System.Web.Util"%>
try{
MailMessage MyMail = new MailMessage();
MyMail.To = "who";
MyMail.From = "you";
MyMail.BodyFormat = MailFormat.Html;
MyMail.Body = "sometext";
SmtpMail.Send(MyMail);
}
catch(Exception){}
|