| can be useful when creating messages offline.
Sending a Message As previously mentioned, sending an e-mail is a relatively simple thing to do. The System.Web.Mail.MailMessage class represents the message to be sent. E-mail messages are constructed by using instances of this class. This class contains properties such as To, From, and Subject that allow you to control the message being sent. Attachments can be created through instances of the System.Web.Mail.MailAttachment and then added to the MailMessage through the Attachments collection of the MailMessage. The message is then delivered through the System.Web.Mail.SmtpMail class.
Sending a Message Sample Code The following sample code contains a C#-based Windows Console application that shows how to send an e-mail message. By not specifying that the SmtpMail.SmtpServer property is not set, the localhost is used by default. You need to make sure to add a reference to the System.Web.dll because this is a console application and not an ASP.NET application.
using System; using System.Web.Mail;
namespace CodeGuru.SendMail { /// <summary> /// Test console application to demonstrate sending e-mail. /// </summary> class TestMail { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { TestMail.Send("testuser@codeguru.com", "mstrawmyer@crowechizek.com", &nb 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> |