Use jmail to send emails in Asp.net

Source: Internet
Author: User

Currently, most emails require stmp authentication,
. Net
System. Web. util
System. Web. Mail
No.
I write this articleArticleI hope it will help you with your development projects.

Find a component namedJmail
You can find it online, download it, and install it.
Reference jmail. DLL to the Project

Figure 1:

Private void button#click (Object sender, system. eventargs E)
{

Jmail. Message jmail = new jmail. Message ();

Datetime T = datetime. now;
String subject = "from email. Net ";
String body = "12:12:12 ";
String fromemail = "ljt21@163.com ";
String toemail = "xiao-maolover@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, default: "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 = "ljt21 ";
// Sender's email password
Jmail. mailserverpassword = "****";
// 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 = body + T. tostring ();
// Jmail sending Method
Jmail. Send ("smtp.163.com", false );
Jmail. Close ();
}
So OK ..!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.