Jmail sends emails and garbled attachments. Solution: Share

Source: Internet
Author: User

The specific usage of Jamil to send mail:

First, we need to download the components of Jamil. dll, add and reference using jmail, and then register them on the local machine or server.

Copy jmail. dll to the system32 directory of the server, start-run-cmd-enter regsvr32 jmail. dll, register successfully, and write the code.

The Code is as follows (method)

Copy codeThe Code is as follows:
Using jmail;
Protected void sendMail (String sender, String senderMail, String receiver er, String subject, String content)
{

Jmail. MessageClass jmMessage = new jmail. MessageClass ();

// Set the character set

JmMessage. Charset = "gb2312 ";

// Sender's email address

JmMessage. From = senderMail;

// Sender's name

JmMessage. FromName = sender;

// Set the topic

JmMessage. Subject = subject;

// Set content

JmMessage. Body = content;

// Set the recipient's email address

JmMessage. AddRecipient (receiver ,"","");

// Set the username and password for logging on to the mailbox

JmMessage. MailServerUserName = "ss ";

JmMessage. MailServerPassWord = "ss ";

// Set the smtp server address

If (jmMessage. Send ("smtp.163.com", false ))
{

Response. Write ("<script> alert ('sent successfully') </script> ");

}

Else

Response. Write ("<script> alert ('www .jb51.net failed to send ') </script> ");

}

The above is the specific usage of Jmail!

I want to add an attachment as follows:
Copy codeThe Code is as follows:
Jmail. AddAttachment ("c: autoexec. bat ")
Jmail.AddAttachment(“myImage.gif ", TRUE)

The following error is returned.

This is a multipart message in MIME format. -- plain Content-Type: text/html; charset = "GB2312" Content-Transfer-Encoding: Quoted-Printable sdfdd -- plain Content-Type: application/octet-stream; name = "=? GB2312? Q? 12d95384-576f-440f-bf15-f8e2417e2791 = 2 EJPG? = "Content-Transfer-Encoding: base64 Content-Description: =? GB2312? Q? 12d95384-576f-440f-bf15-f8e2417e2791 = 2 EJPG? = Content-Disposition: inline; filename = "=? GB2312? Q? 12d95384-576f-440f-bf15-f8e2417e2791 = 2 EJPG? = "Content-ID:

Solution found on the Internet:

Copy codeThe Code is as follows:
AddAttachment (FileName, isInline, ContentType ):

String adds a file-type attachment to the email. If the Inline attribute is set to true, this attachment is an embedded attachment. You can use the addAttachment () method to return the content id, which is very useful when sending HTML emails.

Example:

Copy codeThe Code is as follows:
Jmail. AddAttachment ("c: autoexec. bat ")
Jmail.AddAttachment(“myImage.gif ", TRUE)

Embedded attachments

2. AddURLAttachment (bstrURL, bstrAttachAs, isInline, bstrAuth): String downloads the file from the specified URL and adds it as an attachment. The second parameter "AttachAs" is used to change the file name of the file added as an attachment. If the Inline attribute is set to true, this attachment is an embedded attachment, using ddAttachment () the method returns the content id, which is very useful when sending HTML emails. The last parameter is optional and is used when the server requires authentication.

Example

Copy codeThe Code is as follows:
Jmail.addurlattachment(%w3jmail4.exe%, %w3jmail4.exe ")
Jmail.addurlattachment%w3jmail4.exe ", %w3jmail4.exe", false, "myUserName: mypassword%%%jmail.addurlattachment%dimaclogo.gif%,%dimaclogo.gif", true)

After testing, it seems that it has nothing to do with the two methods. Someone said on the Internet that the Message. ContentType = "text/html" setting was removed (that is, do not set the ContentType attribute). After a try, the Message was successfully sent.

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.