Encoding non-ASCII in mail subject

I'm getting =?ANSI_X3.4-1968?Q? in the subject line of my email with non-ASCII character.
I tried using encodeText from the MimeUtiliy like this but it won't work:
   Message msg = new MimeMessage(session);
            // -- Set the subject and body text --
            msg.setSubject(MimeUtility.encodeText(subject) );How should I go about?
Thank you
Niklas

Thank you very much. I'll make the suggested changes and report back. It's the deafult locale of a virtual dedicated server at secureserver.net which shouldn't be strange. Meanwhile here is the entire method:
  public static void send(String smtpServer, String to, String from
            , String subject, String body, String personal) {
        try {
            log.info("using smtp server:"+smtpServer);
            Properties props = System.getProperties();
            props.put("mail.smtp.host", smtpServer);
            Session session = Session.getDefaultInstance(props, null);
            // -- Create a new message --
            Message msg = new MimeMessage(session);
            // -- Set the FROM and TO fields --
            msg.setFrom(new InternetAddress(from, personal));
            msg.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(to, false));      
            // -- Set the subject and body text --
            msg.setSubject(MimeUtility.encodeText(subject) );
            //msg.setSubject(subject, �UTF-8″);
            //msg.setText(body);
            msg.setContent(body, "text/html");
            // -- Set some other header information --
            msg.setHeader("X-Mailer", "MarketMail");
            msg.setSentDate(new Date());
            // -- Send the message --
            Transport.send(msg);
            //log.info("Message sent OK.");
        } catch (Exception ex) {
            ex.printStackTrace();
   

Similar Messages

  • How Aperture encodes non-ascii chars

    It looks like Aperture uses a way of encode chars as UTF that seem to be bit unusual, many application (especially web apps) expects another way of encoding Unicode chars. The end result is that non-ascii chars comes out really strange.
    When I use applescript to read the IPTC info I need to do something like this before using the data:
    set c_title to normalize unicode p_title without decomposition
    Is there some way of telling Aperture to do this automatically when exporting photos?
    (sorry about the bad use of Unicode terminology but I don't know the area very well)

    I've spent quite a bit of time on this topic - I'm the author of Phoshare http://code.google.com/p/phoshare/, an open-source tool to export images and metadata from iPhoto and Aperture. Storing non-ASCII characters in image metadata is a messy business. If you want to get a taste of it, have a look at the Exiftool FAQ at http://www.sno.phy.queensu.ca/~phil/exiftool/faq.html#Q10 . A quote: "Most textual information in EXIF is stored in ASCII format, ... However *it is not uncommon for applications to write UTF‑8 or other encodings where ASCII is expected*". This leads to all sorts of problems, because the reader will have to make assumptions about the encoding used by the writer.
    In the case of Aperture, I have found that it writes metadata encoded in a way consistent with what most other applications and on-line services expect. Most of the encoding problems I've debugged where caused by bad input data. E.g. the characters were encoded improperly to begin with, but in a way that they still display as expected in some places (like Aperture). Can you try erasing some of the meta data in Aperture, and retype them from scratch (e.g. not copy-paste, which would paste the same stuff right back). Also make sure that you force-updated the preview images, so that the new meta data get written into the files.

  • Sending mail from servers with non-ASCII names

    As part of an effort to internationalize our product we're testing on machines with host names that include non-ASCII characters (accented e's and whatnot). When trying to send mail from these machines we're getting:
    javax.mail.MessagingException: 501 5.5.4 Invalid Address
    at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1634)
    at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:1068)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:458)
    at javax.mail.Service.connect(Service.java:291)
    at javax.mail.Service.connect(Service.java:172)
    at javax.mail.Service.connect(Service.java:121)
    at javax.mail.Transport.send0(Transport.java:190)
    at javax.mail.Transport.send(Transport.java:120)
    at msgsendsample.main(msgsendsample.java:86)
    Looking at a network trace I see the EHLO command being sent as
    EHLO test[0xe9][0xdf]\r\n
    where the machine name is testéß. From a Unicode table 0xe9 0xdf = é ß.
    I found a reference from RFC 5336 (SMTP Extension for Internationalized Email Addresses) that says the hostname in the EHLO must be in the form of ACE (ASCII-compatible encoding) labels:
    3.7.1. The Initial SMTP Exchange
    When an SMTP connection is opened, the server normally sends a
    "greeting" response consisting of the 220 response code and some
    information. The client then sends the EHLO command. Since the
    client cannot know whether the server supports UTF8SMTP until after
    it receives the response from EHLO, any domain names that appear in
    this dialogue, or in responses to EHLO, MUST be in the hostname form,
    i.e., internationalized ones MUST be in the form of ACE labels.
    ACE encoding for my machine would be: java.net.IDN.toASCII("test4éß") --> "xn--testss-eva".
    I'm not sure if this RFC applies in this case - I didn't know anything about the guts of SMTP until yesterday - but it makes sense that you'd need to escape the hostname in the EHLO until you can negotiate capabilities.
    Looking at the JavaMail API it seems that if I were to call SMTPTransport.helo(String domain) myself without going through the higher-level Transport class that maybe I could work around the issue, but I haven't looked into it enough to know if that's feasible.
    Is anyone familiar with this problem? I'm using JavaMail 1.4.2 on Windows 2003 and Exchange as my SMTP server.
    thanks,
    Eric

    Same problem here (or at least in part). Some .mac folders did no longer show any messages, while they were there and could be seen online and with Thunderbird. After your remark I changed the name of a folder which contained a "´" and now it works. It is really strange because there is another folder with a "¨" in it which does not work (I will test if the name change works with this folder as well in a minute) whilst there is another one with such name which works fine. The update really messed up Mail and in Dutch we just use such characters so Mail without supporting them will be rather useless for me...

  • Mail IMAP after 10.5.2 can't read ANY mails in boxes with non-ascii names

    I have Mail with IMAP that connects to a regular MAC OS X Tiger server running IMAP.
    After upgrading to 10.5.2 on the client, Mail can no longer read ANY mails at all in any mailbox whose path contains a non-ascii character!
    Hence: If a box is called 'Övrigt', it only lists the mails in the mail box, but it will not show any of the contents of any of the mails! Hence, I cannot access any of these mails! Catastrophic!
    I have to downgrade to 10.5.1, unless someone knows of a workaround.

    Same problem here (or at least in part). Some .mac folders did no longer show any messages, while they were there and could be seen online and with Thunderbird. After your remark I changed the name of a folder which contained a "´" and now it works. It is really strange because there is another folder with a "¨" in it which does not work (I will test if the name change works with this folder as well in a minute) whilst there is another one with such name which works fine. The update really messed up Mail and in Dutch we just use such characters so Mail without supporting them will be rather useless for me...

  • Can't get the attachment filename out of a Part (with non ascii characters)

    Hello, all and happy new year :)
    My issue is with non ascii filename in attachments... Yes i've read the FAQ : http://www.oracle.com/technetwork/java/faq-135477.html#encodefilename
    I can't get the filename out of the BodyPart for those kind of attachments
    here's my unit test :
         * contains various parts from various mailer encoded in different ways...
         private enum EncodedFileNamePart{
              OUTLOOK("Content-Type: text/plain;\n name=\"=?iso-8859-1?Q?c'estd=E9j=E0no=EBl=E7ac'estcool.txt?=\" \nContent-Transfer-Encoding: 7bit\nContent-Disposition: attachment;\n filename=\"=?iso-8859-1?Q?c'estd=E9j=E0no=EBl=E7ac'estcool.txt?=\" \n\nnoel 2010\n","c'estdéjànoëlçac'estcool.txt"),
              GMAIL("Content-Type: text/plain; charset=US-ASCII; name=\"=?ISO-8859-1?B?ZOlq4G5v62znYWNlc3Rjb29sLnR4dA==?=\"\nContent-Disposition: attachment; filename=\"=?ISO-8859-1?B?ZOlq4G5v62znYWNlc3Rjb29sLnR4dA==?=\"\nContent-Transfer-Encoding: base64\nX-Attachment-Id: f_giityr5r0\n\namluZ2xlIGJlbGxzIQo=\n","déjànoëlçacestcool.txt"),
              THUNDERBIRD("Content-Type: text/plain;\n name=\"=?ISO-8859-1?Q?d=E9j=E0no=EBl=E7acestcool=2Etxt?=\"\nContent-Transfer-Encoding: 7bit\nContent-Disposition: attachment;\n filename*0*=ISO-8859-1''%64%E9%6A%E0%6E%6F%EB%6C%E7%61%63%65%73%74%63%6F;\n filename*1*=%6F%6C%2E%74%78%74\n\njingle bells!\n","déjànoëlçacestcool.txt"),
              EVOLUTION("Content-Disposition: attachment; filename*=ISO-8859-1''d%E9j%E0no%EBl.txt\nContent-Type: text/plain; name*=ISO-8859-1''d%E9j%E0no%EBl.txt; charset=\"UTF-8\" \nContent-Transfer-Encoding: 7bit\n\njingle bells\n","déjànoël.txt"),
              String content=null;
              String target=null;
              private EncodedFileNamePart(String content,String target){
                   this.content=content;
                   this.target=target;
              public Part get(){
                   try{
                   ByteArrayInputStream bis = new ByteArrayInputStream(this.content.getBytes());
                   Part part = new MimeBodyPart(bis);
                   bis.close();
                   return part;
                   catch(Throwable e){
                        return null;
              public String getTarget(){
                   return this.target;
         @Test
         public void testJavamailDecode() throws MessagingException, UnsupportedEncodingException{
              System.setProperty("mail.mime.encodefilename", "true");
              System.setProperty("mail.mime.decodefilename", "true");
              for(EncodedFileNamePart part : EncodedFileNamePart.values())
                   assertEquals(part.name(),MimeUtility.decodeText(part.get().getFileName()),part.getTarget());     
    I take a NullPointerExcepion in the decodeText because getFileName() return null for the EVOLUTION case, and work well with OUTLOOK, THUNDERBIRD and GMAIL.
    Evolution's content type is "Content-Disposition: attachment; filename*=ISO-8859-1''d%E9j%E0no%EBl.txt" wich doesn't look like the other (looks like the RFC 2616 or RFC5987 to do it.)
    How can i handle this situation except by writting my own decoder?
    Thanks for your answers!
    Edited by: user13619058 on 4 janv. 2011 07:44

    Set the System property "mail.mime.decodeparameters" to "true" to enable the RFC 2231 support.
    See the javadocs for the javax.mail.internet package for the list of properties.
    Yes, the FAQ entry should contain those details as well.

  • Problem with non-ASCII file name in content disposition header

    Hi All,
    I am facing some problems with the non-ASCII file name incase of content-disposition header. I read from the RFC 2183 that if the file name contains non-ASCII characters then the same should be encoded before sending to browser. I did the same but realized 2 problems:
    1. The name of the file is truncated in case the file name is slightly long for e.g. �����������j�b�g��������������������������.txt
    2. Also when the same file is opened in notepad, the title is showing encoded name %E6%9C%80%E4%B8%8A%E4%BD%8D.....
    Overall, I feel that the browser is not understanding or responding to the encoded header values.
    Is there any solution to this problem? I am using Microsoft IE 6.0.
    The code snippet is given below:
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
              String fileName = "�����������j�b�g��������������������������.txt";          
              fileName = URLEncoder.encode(fileName, "UTF-8");
              resp.setCharacterEncoding("UTF-8");
              resp.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
              resp.setContentType("application/download-binary");
              String s = "This is inside txt file";
              resp.getOutputStream().write(s.getBytes("UTF-8"));
              return;
         }Any help or pointer would be highly appreciated.
    Thanks and Regards,
    Ashish

    The MIME standards for non-ASCII filenames are not widely implemented.
    Many mailers use an ad hoc method for encoding filenames. JavaMail
    supports both methods, but you need to set properties, such as the
    mail.mime.encodefilename property. See the JavaMail javadocs for
    the javax.mail.internet package.

  • How to send an attached file containing with non-ascii code ?

    Hi,
    I want to send a attaced text file containing with non-ascii code(Traditional Chinese). Is there any way to solve the encoding problem?
    Currently, it transfer into non-meaningful code in receiving side.
    Thanks for the help in advance.

    Here is the code:
    Session _gSession = null;
    MimeMessage message = null;
    Properties props = new Properties();
    props.put("mail.smtp.host", smtpHost);
    _gSession = javax.mail.Session.getInstance(props, null);
    message = new MimeMessage(_gSession);
    message.setFrom(new InternetAddress(emailSender , emailSender));
    InternetAddress ia[] = new InternetAddress[1];
    ia[0] = new InternetAddress(emailReceiver, emailReceiver);
    message.setRecipients(Message.RecipientType.TO, ia);
    message.setSubject("Test Encoding Attached File");
    message.saveChanges();
    BodyPart messageBodyPart = new MimeBodyPart();
    DataSource fds = new FileDataSource("Big5_Code.txt");
    messageBodyPart.setDataHandler(new DataHandler(fds));
    messageBodyPart.addHeader("Content-ID","meme");
    MimeMultipart multipart = new MimeMultipart("related");
    multipart.addBodyPart(messageBodyPart);
    message.setContent(multipart);
    transport.connect();
    transport.send(message);

  • JavaMail with non-ascii file name attachment.

    Hello,
    I add a file to the mail, which file name is a Chinese name. After I sent it and receive in other email client (M$outlook), it could not display the correct file name for the attachment file.
    How can solve this ?

    The MIME standards for non-ASCII filenames are not widely implemented.
    Many mailers use an ad hoc method for encoding filenames. JavaMail
    supports both methods, but you need to set properties, such as the
    mail.mime.encodefilename property. See the JavaMail javadocs for
    the javax.mail.internet package.

  • Can ims5.2p1 do sieve filter searches with non-ASCII chars?

    Particularly, is it possible with the
    Subject header line, which is
    =?xxx?Q?xxxxx?= or =?xxx?B?xxxxx?= encoded
    Resolved the fileinto foldername part, but
    now found that seems like ims's sieve filter
    cannot do non-ASCII matches... Thanks.

    Hi, back! Spent a few hours experimenting and found
    that everything is working great (including the creation
    of international non-ASCII foldernames) when I used
    utf-8 encoding in the sieve filters rules for the
    the match strings and the folder names... at least
    so far so good... for your ref and sorry for bothering.

  • Non-ASCII content in body

    Hi
    When I send non-ASCII content in the body of a mail, the content does not appear correctly in the mail body.
    <BR>
    THe ccode is as below
    msg.setHeader("Content-Transfer-Encoding", "quoted-printable" );
    <BR>
    String a = MimeUtility.encodeText("�later","UTF-8","B");
    <BR>
    msg.setContent(a, "text/html");
    <BR><BR>
    Mail is received as =?UTF-8?B?4oCZbGF0ZXI=?=
    Can anybody help
    Regards
    Syed Niaz

    Hi!
    Your code looks a bit messy.
    If you are sending non-ascii data, you should use a DataHandler and a DataSource to add your data to the mail's body instead of using MimeUtility.encode()
    Hope this helps.

  • Non ascii characters being sent from a parameter in a form

    Hi!
    I have seen many topics posted on passing non ascii characters through parameters from one servlet to another and converting them into whatever format is necessary.
    However, I have not seen anyone answer the following question. I have a jsp page (html) with the character encoding set to utf-8. The user inputs some data in to a text field which is inside a form. The data could be in non ascii characters such as hebrew or arabic. This form is then sent to another jsp where i try to retreive the data from teh text field. No matter what i do, i cannot get the data presented correctly. It is either question marks or other wierd symbols.
    I have tried every permetation of encoding of the actual html page, the ecoding of the string from request.getParameter etc but it still is not presented on the new html page correctly.
    Can anyone help??
    Spencer

    Ok, I solved the problem.
    I had to put at the top request.setCharacterEncoding("utf-8");
    Spencer

  • Folders that having non-ascii chars are not displaying on MAC using JFileChooser

    On MAC OS X 10.8.2, I have latest Java 1.7.25 installed. When I run my simple java program which allows me to browse the files and folders of my native file system using JFileChooser, It does not show the folders that having non-ascii char in there name. According this link, this bug had been reported for Java 7 update 6. It was fixed in 7 Update 10. But I am getting this issue in Java 1.7.21 and Java 1.7.25.
    Sample Code-
    {code}
    public class Encoding {
    public static void main(String[] arg) {
    try {
    //NOTE : Here at desktop there is a folder DKF}æßj having spacial char in its name. That is not showing in file chooser as well as while is trying to read for FILE type, it is not identify by Dir as well as File - getting File Not Found Exception
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (IllegalAccessException ex) {
    Logger.getLogger(Encoding.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedLookAndFeelException ex) {
    Logger.getLogger(Encoding.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
    Logger.getLogger(Encoding.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
    Logger.getLogger(Encoding.class.getName()).log(Level.SEVERE, null, ex);
    JFileChooser chooser = new JFileChooser(".");
    chooser.showOpenDialog(null);
    {code}

    Hi,
    Did you try this link - osx - File.list() retrieves file names with NON-ASCII characters incorrectly on Mac OS X when using Java 7 from Oracle -…
    set the LANG environment variable. It's a GUI application that I want to deploy as an Mac OS X application, and doing so, the LSEnvironment setting
    <key>LSEnvironment</key> <dict> <key>LANG</key> <string>en_US.UTF-8</string> </dict>

  • Non-ASCII character in Email field

    Hi Guys,
    I am trying to enter non-english characters in Email field of user form, but OIM throws an error that "A non-Ascii character has been entered". I have also tried to turn off the AppFirewall Filter in xlConfig.xml file but no help. Is there any way thay I can enter non-Ascii characters in Email field?
    Regards,
    Rahul

    .oO(surfinIan)
    >I have a script that converts a ms word document to text
    then uploads that to a
    >blob field on a mysql db.
    > During the conversion some characters my not be
    recognised. When i then call
    >up the blob for display on the browser...those characters
    show up as unknown
    >characters with a ? or box. Is there a way to
    preg_replace those unknown
    >characters before displaying them.
    What about fixing the encoding problem instead? If chars get
    lost during
    such a transfer
    document->script->database->script->browser it's always
    an encoding problem somewhere down the road.
    The recommendation these days is to use UTF-8, which avoids
    most of
    these old problems. You just have to make sure that your
    documents are
    properly stored as UTF-8 in the database and delivered as
    such to the
    script and the browser, then you don't have to worry about
    special chars
    anymore.
    That's just the general idea. I can't be more specific, since
    I don't
    know your conversion script or the database structure.
    Micha

  • UploadedFile and filenames with non-ascii chars

    Hi
    I'm using an UploadedFile object in my web app, and all works fine. However, when I try to upload a file, with a filename containing non-ascii chars (e.g. Spanish), I see that the getBytes method returns an empty byte array, the filename is not stored correctly (the non-ascii chars are lost, replaced by another representation), and that the content-type is application/octet-stream instead of image/png as supposed to be.
    If I rename that same file to have only ascii chars - everything is back to normal.
    How can I upload files with non-ascii chars in their name?

    Hi, back! Spent a few hours experimenting and found
    that everything is working great (including the creation
    of international non-ASCII foldernames) when I used
    utf-8 encoding in the sieve filters rules for the
    the match strings and the folder names... at least
    so far so good... for your ref and sorry for bothering.

  • Problems with non-ASCII characters on Linux Unit Test Import

    I found a problem with non-ASCII characters in the Unit Test Import for Linux.  This problem does not appear in the Unit Test Import for Windows.
    I have attached a Unit Test export called PROC1.XML  It tests a procedure that is included in another attachment called PROC1.txt. The unit test includes 2 implementations.  Both implementations pass non-ASCII characters to the procedure and return them unchanged.
    In Linux, the unit test import will change the non-ASCII characters in the XML file to xFFFD. If I copy/paste the the non-ASCII characters into the Unit Test after the import, they will be stored and executed correctly.
    Amazon Ubuntu 3.13.0-45-generic / lubuntu-core
    Oracle 11g Express Edition - AL32UTF8
    SQL*Developer 4.0.3.16 Build MAIN-16.84
    Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)
    In Windows, the unit test will import the non-ASCII characters unchanged from the XML file.
    Windows 7 Home Premium, Service Pack 1
    Oracle 11g Express Edition - AL32UTF8
    SQL*Developer 4.0.3.16 Build MAIN-16.84
    Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
    If SQL*Developer is coded the same between Windows and Linux, The JVM must be causing the problem.

    Set the System property "mail.mime.decodeparameters" to "true" to enable the RFC 2231 support.
    See the javadocs for the javax.mail.internet package for the list of properties.
    Yes, the FAQ entry should contain those details as well.

Maybe you are looking for

  • ERROR in Patch BASIS  SAPKB62043 on 4.7 server

    Hi All I have installed a fresh SAP server 4.7 on windows 2003 server  /oracle 9.2.0.7 and done all post installation steps. I need to install BASIS patch and ABAP Patch I started with BASIS patch 42 it was done successfully after that I tried to ins

  • I am getting an error 502 when trying to download lion?

    When i click install in apple store, i get the message The sever gave an error during download :502 bad gateway. What is this and how can i get around it.

  • Page format for SAP-Script not working in 4.6C

    Hi all, I have a problem regarding check printing. I am using SAP version 4.6C The size of paper for check printing is           width  = 231 mm           Height = 304 mm So for this I have created a new page format with these details in SPAD. Then I

  • _sans font problem or bug..!?

    while using _sans font with 11px, the edge of W is getting cut. But wen i change to 12px or 10px it works fine... ActionScript Code: <mx:TextArea id="_txt" htmlText="{txtStr.toUpperCase()}" width="600" height="200" styleName="subSectionTextStyle" />

  • HT1338 still asking for adobe flash player even when I downloaded it already

    I downloaded adobe flash player as directed but still cannot open my teacher's email link, still asking for my adobe flash player.