Asp.net jmail email sending code

Source: Internet
Author: User

To send an email with Jamil, you must download the Jamil software and install it before using it. Then copy Jamil. DLL to the bin directory to add references.

Using system;
Using system. Data;
Using system. Data. sqlclient;
Using system. configuration;
Using system. Web. util;
Using system. Web. mail;
Using system. net. configuration;
Namespace hottiger. Web
{
Public class sendemail
{
/// <Summary>
/// Send an email
/// </Summary>
/// <Param name = "mailtitle"> title </param>
/// <Param name = "mailcontent"> content </param>
/// <Param name = "mailto"> to whom the message is sent, multiple users can send messages at the same time, and multiple users are separated by ";" </param>
/// <Returns> </returns>
Public static bool email (string mailtitle, string mailcontent, string mailto)
{
Try
{
Jmail. Message jmail = new jmail. Message ();
String subject = mailtitle;
String body = mailcontent;
String fromemail = configurationmanager. receivettings ["mailname"];
String toemail = mailto;
// 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
String [] arraymail = mailto. Split (';');
For (INT I = 0; I <arraymail. length; I ++)
{

Jmail. addrecipientbcc (arraymail [I], "");
}
Jmail. From = fromemail;

// Sender's email user name
Jmail. mailserverusername = configurationmanager. receivettings ["mailuser"];
// Sender's email password
Jmail. mailserverpassword = configurationmanager. receivettings ["mailpwd"];
// Set the mail title
Jmail. Subject = subject;
// Email content
Jmail. Body = body;
// Jmail sending Method
Jmail. Send (configurationmanager. receivettings ["SMTP"], false );
Jmail. Close ();
Return true;
}
Catch
{
Return false;
}
}
}

}

 

<! -- Mailbox configuration web. config -->
<Add key = "SMTP" value = "smtp.sina.com"/>
<Add key = "mailuser" value = "XXX"/>
<Add key = "mailpwd" value = "XXX"/>
<Add key = "mailname" value = "xxx@sina.com"/>

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.