Send an email using .NET

xiaoxiao2021-03-06  115

Send an email using .NET

If you have used the ASP to send an email, you probably use cdonts, but in .NET, the function of sending the mail has been encapsulated.

The namespace of the .NET Framework's System.Web.mail, use this namespace, you can easily build a program that sends an email, and you need to schedule SMTP servers in Windows. System.Web.mail Namespace: This naming control contains the following objects and three properties: object included: MaiTtachment: Objecttpmail with email attachments: Mail body SMTPMAIL: Responsible for sending mail SMTP protocols. Properties List: MailEncoding: Mail Code (Base64, UuEncode) MailFormat: Mail format (HTML Hypertext Format, Text Plain Wen] MailPriority: Mail Priority (High, Medium, Low)

Build a MailMessage object: The MailMessage object is the carrier body of the message, usually you can build a MailMessage object first, and then set its properties.

Build a mail program, some of the commonly used properties: attachments: mail attachment BCC: Dark address Body: Mail body BodyFormat: Mail format (HTML, TEX) CC: Cc address from: Message Address Priority: Mail High, Medium, Low Subject: Mail Top TO: Receiver Address UrlContentBase: URL encoding in HTML format URLContentLocation: Mail information priority (High, Medium, Low)

After using SMTPMAIL to build a mailmssage object, you will also need to use another object -smtpmail- to send emails, and SMTPMail has a very

Important method: Send, this method has two different usage, one of which can only send the entire MailMessage object: SMTPMAIL.SEND (MyEmailObject); another allows you to specify senders, collect mail addresses, email topics, mail themes, Then send out: SMTPMail.send (strfrom, strs, strsubject, strbody); example: now, let's take a look at a complete example, in this example, I first create a MailMessage object, then set some properties, Finally, use the SMTPMail object to send it out: <% @ page language = "c #"%>