I have a javamail automatic email sending program. Which of the following experts can help me to see why Chinese garbled characters are sent?

Source: Internet
Author: User

 

Sad... I have transcoded it too. But I still cannot. Experts, help me ....

 

<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "Java. util. *, javax. Mail. *" %>
<% @ Page import = "javax. Mail. Internet. *, javax. Mail. *" %>
<%!
Public String codetostring (string Str ){
String Ss = STR;
Try {
Byte tempb [] = ss. getbytes ("ISO-8859-1 ");
Ss = new string (tempb, "gb2312 ");
Return SS;
}
Catch (exception e ){
Return SS;
}
}
%>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
</Head>

<Body>
<%
Try {
// String to_mail = codetostring (request. getparameter (""));
// String to_titile = codetostring (request. getparameter ("title "));
// String to_content = codetostring (request. getparameter ("content "));

String to_mail = codetostring ("331062104@qq.com"); // recipient
String to_title = codetostring ("mail title ");
String to_content = codetostring ("email content ");

// Sun. Misc. base64encoder ENC = new sun. Misc. base64encoder ();
// Message. setsubject ("=? Gb2312? B? "+ Enc. encode () + "? = ");


Properties props = new properties ();
Props. Put ("mail. SMTP. Host", "smtp.126.com ");
Props. Put ("mail. SMTP. Auth", true );
Session S = session. getinstance (props );
S. setdebug (true );

Mimemessage message = new mimemessage (s );

Internetaddress from = new internetaddress ("mianye349896094@126.com"); // sender's mailbox
Internetaddress to = new internetaddress (to_mail );


Message. setfrom (from );
Message. setrecipient (message. recipienttype. To, );

//
Message. setsubject (to_title );
Message. settext (to_content );
Message. setsentdate (new date ());

Message. savechanges ();
Transport transport = S. gettransport ("SMTP ");
Transport. Connect ("smtp.126.com", "mianye349896094@126.com", "password ");
Transport. sendmessage (message, message. getallrecipients ());
Transport. Close ();
%>
<Div> sent successfully! </Div>
<%

}
Catch (exception e ){
Out. println ("failed to send ");
}
%>
</Body>
</Html>

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.