Just a friend of mine sent an email in Asp.net to share it!
Using system;
Using system. configuration;
Using system. Data;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. mail;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
}
Protected void btnsend_click (Object sender, eventargs E)
{
Mailmessage mailmsg;
// Create an email message
Mailmsg = new mailmessage ();
// Sending Address
Mailmsg. From = txtfromemail. Text. Trim ();
// Receiving address
Mailmsg. To = txttargetemail. Text. Trim ();;
// Set the mail body type
Mailmsg. bodyformat = mailformat. text;
// Email Subject
Mailmsg. Subject = txtsubject. Text. Trim ();]
// Create an attachment object
Mailattachment MA = new mailattachment (F. Value); // complete path of the f. Value attachment
Mailmsg. attachments. Add (MA );
// Email content
Mailmsg. Body = txtcontext. Text. Trim ();
// The IP address of the server. Because we use a local virtual SMTP server, you only need to enter the local IP address.
Smtpmail. smtpserver = "127.0.0.1 ";
/// Authentication is required for the following three email servers.
Mailmsg. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1 ");
// Set the authentication username (Change username to your authentication username)
Mailmsg. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "username ");
// Set the verification password (Change PWD to your verification password) // the sender's username
Mailmsg. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", "PWD"); // Email Password
Smtpmail. smtpserver = "smtp.126.com"; // select another server
Smtpmail. Send (mailmsg );
}
}
Note: To set the SMTP virtual server on the local machine, the above IP address must be in the authorized IP address list. The final mail sent by the SMTP Virtual Server