Code
Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Public partial class mailtest: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
String bodystr = "";
Bodystr = "one test email ";
Jmail. Message jmail = new jmail. Message ();
// Datetime T = datetime. now;
String subject = "one test email ";
String fromemail = "12345@qq.com ";
String toemail = "ysclc@163.com ";
// Silent attribute: If set to true, jmail will not throw an exception error. jmail. Send () will return true or false Based on the operation results
Jmail. Silent = true;
// Logs created by jmail, provided that the loging attribute is set to true
Jmail. Logging = true;
// Character set. The default value is "US-ASCII"
Jmail. charset = "gb2312 ";
// Contentype of a letter. The default value is "text/plain"): If you send an email in HTML format, change it to "text/html.
Jmail. contenttype = "text/html ";
// Add recipient
Jmail. addrecipient (toemail ,"","");
Jmail. From = fromemail;
// Sender's email user name
Jmail. mailserverusername = "12345 ";
// Sender's email password
Jmail. mailserverpassword = "password"; // QQ Password
// Set the mail title
Jmail. Subject = subject;
// Add attachments to the email. (If there are multiple attachments, you can add jmail. addattachment ("C: \ test.jpg", true, null. [Note]: add an attachment to delete the above jmail. contenttype = "text/html. Otherwise, garbled characters will appear in the email.
// Jmail. addattachment ("C: \ test.jpg", true, null );
// Email content
Jmail. Body = bodystr;
// Jmail sending Method
If (jmail. Send ("smtp.qq.com", false ))
{
Response. Write ("OK ");
}
Else
{
Response. Write ("no ");
}
Jmail. Close ();
}
}
The above code is a case
Procedure
- Download jmail. dll (click to download)
- Register the jmail component locally (place jmail. dll in the System32 folder on the system disk, and run cmd to enter regsvr32 jmail. dll)
- Vs adds a reference to jmail. dll.
- Run the code above to test the application. You can write your own class as needed.