Send mail via smtp server:
// TxtFrom. text is the sender's email address, and txtGet. Text is the recipient's email address.
MailMessage Mail = new MailMessage(this.txt From. Text, this.txt Get. Text );
Mail. Subject = this.txt Subject. Text. Trim (). ToString ();
Mail. Body = this. richTextBox1.Text. Trim (). ToString ();
SmtpClient Client = new SmtpClient ("smtp.126.com", 25); // instance a SmtpClient class
// Txtusername is the sender's email account, and txtpwd is the email password
Client. Credentials = new System. Net. NetworkCredential (txtusername. Text, txtpwd. Text );
// Client. Host = "smtp.126.com ";
// Attachment
If (txtAttach. Text. Length> 0)
{
// Add an attachment
Mail. Attachments. Add (new Attachment (txtAttach. Text, MediaTypeNames. Application. Octet ));
}
// Send an email
Client. Send (Mail );
The program interface is designed as follows: