The list of COM components that can be referenced shows that there is a COM component named Microsoft CDO for Exchange 2000 library, which we can use to connect to the SMTP server, use the user name/password to send the email.
The following is an example of implementation:
SMTP server uses SMTP-SRV, login user name is David Euler, send mailbox is davidEuler@test.com, send to test@test.com/
1) In resource manager, add reference and the COM component of Microsoft CDO for Exchange 2000 library;
2 ). edit the user interface, such as fromtextbox, totextbox, cctextbox, bcctextbox, subjecttextbox, messagetextbox, passwordtextbox, smtptextbox, and set the textmode attribute of messagetextbox to "multiline". the textmode attribute of passwordtextbox is "password", add the response prompt tag, and add the send button.
3) after entering the user name, password, and SMTP server, the user clicks the send button to send the email,
The Click Event code of the send button is as follows:
CDO. Message omsg = new CDO. Message ();
// Omsg. From = fromtextbox. text;
Omsg. To = totextbox. text;
Omsg. Subject = subjecttextbox. text;
Omsg. textbody = messagetextbox. text;
Omsg. Cc = cctextbox. text;
Omsg. bcc = bcctextbox. text;
String username;
String emailfrom;
String Password = passwordtextbox. Text. tostring (). Trim ();
Username = fromtextbox. Text. Trim ();
Emailfrom = username. Replace ("", "") + "@ test.com ";
Omsg. From = emailfrom;
CDO. iconfiguration iconfg;
ADODB. Fields ofields;
Iconfg = omsg. configuration;
Ofields = iconfg. fields;
Ofields ["http://schemas.microsoft.com/cdo/configuration/sendusing"]. value = 2;
Ofields ["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"]. value = emailfrom;
Ofields ["http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress"]. value = emailfrom;
Ofields ["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"]. value = username;
Ofields ["http://schemas.microsoft.com/cdo/configuration/sendusername"]. value = username;
Ofields ["http://schemas.microsoft.com/cdo/configuration/sendpassword"]. value = password;
Ofields ["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"]. value = 1;
Ofields ["http://schemas.microsoft.com/cdo/configuration/smtpserver"]. value = smtptextbox. Text. Trim (); // smtp.163.com
Ofields. Update ();
Try
{
Omsg. Send ();
Omsg = NULL;
Response. Write ("<SCRIPT> alert ('" + "message sent successfully! "+" '); </SCRIPT> ");
}
Catch (exception ex)
{
Response. Write ("<SCRIPT> alert ('" + "failed to send:" + "'); </SCRIPT> ");
String exmsg = "username:" + username +
"Passwd:" + password +
"SMTP:" + smtptextbox. Text. Trim ();
Response. Write ("<SCRIPT> alert ('" + exmsg + "'); </SCRIPT> ");
Failedlabel. Text = ex. Message. tostring ();
}......
Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1539991