Send an email using the jmail component

Source: Internet
Author: User

There have been a lot of Introduction to jmail on the Internet. I recorded my experience, helping beginners like me as well as accumulate.
Jmail is mainly used in the following aspects:
1. Installation: to install the jmail component on a machine, it is actually a "jmail. dll", which is usually installed

C: \ windows \ system32 \ directory. If you only download the jmail. dll file, you can manually put it in this directory.

It should also work. I have never tried it.
2. Registration: automatic installation is generally automatically registered at the same time, so you do not need to care about this. But only the jmail. dll file is downloaded.

Manually register by yourself. The registration method is as follows: in the command line window, run the command "regsvr c: \ windows \ system32 \ jmail. dll". Of course

Specify the file path.
3. Reference: Copy jmail. DLL to the bin directory of the web site and add com references to the site.
4. Write the Code as follows: Remember to reference the namespace.

Using system;
Using system. Data;
Using system. configuration;
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;

 

Using jmail;

Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}
Protected void button#click (Object sender, eventargs E)
{
Jmail. messageclass mail = new jmail. messageclass ();

Datetime T = datetime. now;
String subject = "jmail test! "+ T. tostring ();
String body = "Hello world! <Br/> ";


String fromemail = "mymail@126.com ";
String toemail = "mail@china.com ";
// Silent attribute: If set to true, jmail will not throw an exception error. jmail. Send () will return true based on the Operation Result

Or false
Mail. Silent = true;
// Logs created by jmail, provided that the loging attribute is set to true
Mail. Logging = true;
// Character set. The default value is "US-ASCII" gb2312.
Mail. charset = "UTF-8 ";
Mail. Encoding = "base64 ";
// Contentype of the letter. The default value is "text/plain"): If you send an email in HTML format, change it to "text/html"

You can.
Mail. contenttype = "text/html ";
// Add recipient
Mail. addrecipient (toemail ,"","");
Mail. From = fromemail;
// Sender's email user name
Mail. mailserverusername = "mymail@126.com ";
// Sender's email password
Mail. mailserverpassword = "123 ";
// Set the mail title
Mail. Subject = subject;
// Add attachments to the email. (If there are multiple attachments, add jmail. addattachment ("C: \ test.jpg", true, null );).

You can do it. [Note]: add an attachment to delete the above jmail. contenttype = "text/html. Otherwise, garbled characters will appear in the email.
// Mail. addattachment ("C: \ test.jpg", true, null );
// Email content
Mail. Body = body + T. tostring ();
// Jmail sending Method
If (mail. Send ("smtp.126.com", false ))
{
Response. Write ("<script language = 'javascript '> alert (' OK! ') </SCRIPT> ");
}
Else
{
Response. Write ("<script language = 'javascript '> alert ('false! ') </SCRIPT> ");
Response. Write (mail. errorcode. tostring () + "<br/>" + mail. errormessage. tostring () +

"<Br/>" + mail. errorsource. tostring () + "<br/> ");
}
Mail. Close ();
}
}

// Encountered Error
The common error is: 'The message was undeliverable. all servers failed to receive the message, which is actually an error returned by jmail, not produced by ASP code. The root cause is that the mail server rejects the jmail request.

The reason is that the server does not provide the SMTP service or has not enabled the SMTP service, or the 'prohibit mail relay service' option is enabled on the server side, that is to say, a program that is not in its allowed IP segment or a specified range of space cannot use its SMTP service. Solution: Use a mail server that supports SMTP. Use an email server that supports external jmail to apply for authentication and send emails. Best: Enterprise post offices that use their own SMTP functions. Because free post offices outside may have some special settings, it is better to prevent spam and identity theft!

Jmail must be verified by the email server first.
If your server does not support SMTP or your account cannot use the SMTP service
Then it cannot be sent.

163 users who used to activate the pop and SMTP services by default
However, new users are not activated and need to pay for it.

To determine whether pop and SMTP can be used in a mailbox, you can use Foxmail and other email software to check whether the mail can be received.

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.