Reprinted from: http://blog.csdn.net/fhbcn/archive/2008/03/01/2137819.aspx
1. send an emailProgram(Use the class under system. Web. Mail)
Public Static Bool Sendmail ( String Mailhead, String Mailbody, String Emailadd)
...{
If (Emailadd ! = "" )
...{
// Create a mailmessage object
System. Web. Mail. mailmessage mailmsg = New System. Web. Mail. mailmessage ();
// Set the recipient's email address
Mailmsg. = Emailadd;
// Set the sender's email address
Mailmsg. From = " Wicresoft@126.com " ;
// Set Email Subject
Mailmsg. Subject = Mailhead;
// Set email content
Mailmsg. bodyformat = System. Web. Mail. mailformat. html;
If (Mailbody ! = "" )
...{
Mailmsg. Body = Mailbody;
// Set to support server Verification
Mailmsg. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate " , " 1 " );
// Set User Name
Mailmsg. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/sendusername " , " Wicresoft " );
// Set User Password
Mailmsg. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/sendpassword " , " Wangwei " );
Try
...{
// Set email sending server 202.108.5.142
System. Web. Mail. smtpmail. smtpserver = " 202.108.5.142 " ;
// Send email
System. Web. Mail. smtpmail. Send (mailmsg );
Return True ;
}
Catch
...{
Return False ;
}
}
Else
Return False ;
}
Else
Return False ;
}
This article is from the csdn blog. For more information, see http: // Blog.csdn.net/fhbcn/archive/2008/03/01/4107819.aspx
2. net2.0 provides an alternative (using system. NW)
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. net. mail;
Namespace Mailsender
...{
Class Program
...{
Static String Strhost = String . Empty;
Static String Straccount = String . Empty;
Static String Strpwd = String . Empty;
Static String Strfrom = String . Empty;
Static Void Main ( String [] ARGs)
...{
Strhost = " Smtp.163.com " ; // Stmp server address
Straccount = " Jailu " ; // SMTP service account
Strpwd = " 123456789 " ; // SMTP service Password
Strfrom = " Jailu@163.com " ; // Sender's email address
Console. writeline (Sendmail ( " Jailu@qq.com " , " This is a test email. " , " This is the body of a test email. " ) ? " Success " : " Unsuccess " );
Console. Readline ();
}
/**/ /// <Summary>
/// Send email
/// </Summary>
/// <Param name = "to"> Recipient email address </Param>
/// <Param name = "title"> Email Subject </Param>
/// <Param name = "content"> Body content </Param>
/// <Returns> </returns>
Static Bool Sendmail ( String To, String Title, String Content)
...{
Smtpclient = New Smtpclient ();
Smtpclient. deliverymethod = Smtpdeliverymethod. Network; // Specify email sending Method
Smtpclient. Host = Strhost ;; // SMTP Server
Smtpclient. Credentials = New System. net. networkcredential (straccount, strpwd ); // Username and password
Mailmessage = New Mailmessage (strfrom, );
Mailmessage. Subject = Title; // Topic
Mailmessage. Body = Content; // Content
Mailmessage. bodyencoding = System. Text. encoding. utf8; // Body code
Mailmessage. isbodyhtml = True ; // Set to HTML Format
Mailmessage. Priority = Mailpriority. High; // Priority
Try
...{
Smtpclient. Send (mailmessage );
Return True ;
}
Catch
...{
Return False ;
}
}
}
}
This article is from the csdn blog. For more information, see http: // Blog.csdn.net/fhbcn/archive/2008/03/01/4107819.aspx