The "System. Net. Mail" provided in. Net FrameWork 2.0 can be easily implemented. This article lists three methods for sending:
1. Use Localhost;
2. Use normal SMTP;
3. SMTP over SSL;
For example:
1. Use LocalHost
Public void SendMailLocalhost () {System. net. mail. mailMessage msg = new System. net. mail. mailMessage (); msg. to. add ("a@a.com"); msg. to. add ("B @ B .com");/** msg. to. add ("B @ B .com"); * msg. to. add ("B @ B .com"); * msg. to. add ("B @ B .com"); can be sent to multiple people */msg. CC. add ("c@c.com");/** msg. CC. add ("c@c.com"); * msg. CC. add ("c@c.com"); can be copied to multiple people */msg. from = new MailAddress ("a@a.com", "AlphaWu", System. text. encoding. UTF8);/* the preceding three parameters are respectively the sender address (which can be written as needed), the sender name, And the encoding */msg. subject = "this is a test email"; // mail title msg. subjectEncoding = System. text. encoding. UTF8; // The Message Title code msg. body = "email content"; // message content msg. bodyEncoding = System. text. encoding. UTF8; // The Message Content Encoding msg. isBodyHtml = false; // whether the message is an HTML message msg. priority = MailPriority. high; // mail priority SmtpClient client = new SmtpClient (); client. host = "localhost"; object userState = msg; try {client. sendAsync (msg, userState); // client is a little simpler. send (msg); MessageBox. show ("sent successfully");} catch (System. net. mail. smtpException ex) {MessageBox. show (ex. message, "sending email error ");}}
2. Use normal SMTP