In Mail question mark is coming in place of special characters | Community
Skip to main content
Level 4
November 1, 2016

In Mail question mark is coming in place of special characters

  • November 1, 2016
  • 4 replies
  • 11744 views

Hi All,

I have a simple abc.txt email template under /etc/notification/email .

**************************abc.txt****************************

<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<pre style="white-space:normal;">
    <table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">
         <br/><br/>
          ${pages} 
    </table>
</pre>
</body>
</html>

Whenever off time property will be changed the mail will be triggered. For this code is written as below.

In onevent we are calling below

emailService.sendEmail(EMAIL_TEMPLATE_PATH,emailParamsThirty,groupEmail);

******************************EMAIL CODE*********************************

private Map<String, String> prepareEmailParams(ResourceResolver resourceResolver, String pagePath)  {                
                final Map<String, String> emailParams = new HashMap<String,String>();        
                String pagePath = resourceResolver.map(page.getPath()); 
                strBufferPages.append("<li><a href='").append(pagePath).append(".html").append("'>");
                strBufferPages.append("第65回日");  --------THIS ONE WHEN WE WILL GET IN MAIL IT IS COMING LIKE ?65??

                strBufferPages.append("</a></li>");
                strBufferPages.append("</ul> </td></tr>");                
                //LOGGER.info("pagesExists ========== +++++++++++++ ==== " + strBufferPages.toString());
                emailParams.put("pages", strBufferPages.toString());                
    }

But When I am getting mail , the UTF-8 is removed and it is coming like ?65??

Can anybody please help me on this.

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

smacdonald2008
Level 10
November 1, 2016

Looks like an encoding issue. Set the encoding in the message content header - for example:

msg.setContent(message, "text/plain; charset=UTF-8");

Level 4
November 1, 2016

Hi Scott,

Yes it is an encoding issue. I am using AEM 6.0 SP1. Also I have set the default parameter encoding as UTF-8 , as shown in below screenshot.

I am new to AEM. So can you please tell me where can I Set the below encoding in the message content header?

kolpur
Level 2
November 1, 2016

You might need to use the following:

sb.append(new String(bytes, charset));

Level 4
November 1, 2016

Hi Srini,

I tried the code suggested by you in my java code. But still I am getting Question marks (?65??).

******************CHANGED CODE*******************

                String pageTitle1 = "第65回日";
                pageTitle1  = new String(pageTitle1.getBytes("UTF-8"));

                strBufferPages.append("<li><a href='").append(externLink).append(".html").append("'>");
                strBufferPages.append(pageTitle1);
                strBufferPages.append("</a></li>");
                strBufferPages.append("</ul> </td></tr>");

kolpur
Level 2
November 2, 2016

Hi Sunita,

1. Try to put the hard-coded Japanese string in the mail (abc.txt) directly and check if you are getting it right - if this is working, then it means you are not encoding it properly while setting the params

2. If above works, try setting the Japanese string only (new String(pageTitle.getBytes("UTF-8"))), then use the StringBuilder to append the full html.

kautuk_sahni
Community Manager
Community Manager
November 3, 2016

Hi 

Pleas refer to this community article:-

Link:- http://adobeaemtips.blogspot.in/2015/11/utf-8-encoding-in-aem.html

// UTF- 8 Encoding in AEM

    AEM 6.1 : Go to Apache Sling Request Parameter Handling . Change the Default Parameter Encoding to "UTF-8"

    Encoding & Decoding while posting data to Sling Servlet :

    Decoding  in the Servlet.

    String id = java.net.URLDecoder.decode(request.getParameter("id"), "UTF-8");

    Encoding data before posting to a  Servlet

    String id= java.net.URLEncoder.encode("cust", "UTF-8"); 

    Set charset encoding in a JSP :

    <%@ page contentType="text/html;charset=UTF-8" %> 
    <%@ taglib uri="/libs/CFC/resources/jstl/c.tld" prefix="c" %> 
    <form method="post"> 
    <input name="searchterm" value="<c:out value="${param.searchterm}" />" />
    <input type="submit" /> 

    </form>

 

Link:-http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__bgsh-hi_all_i_wantto.html

// Unicode escape sequences: \u followed by 4 hexadecimal digits (e.g.: \u0022 for ", \u0027 for ', \u003c for <, or \u003e for >

 In HTL (Formerly known as Sightly), 

 Use:-   ${ '{0} {1} {2} {3}' @ format=['\u003e','\u003C', '\u002F', '\u005C']}

 This will print :-        > < / \

 

Link:- https://helpx.adobe.com/experience-manager/using/post_chars.html

// Posting Special Characters to Adobe Experience Manager

 

I hope this would help you.

~kautuk

Kautuk Sahni
April 27, 2020

I also faced similar issue. Unicode character(special characters) passed as a request parameter getting converted to question mark(?).

Reason : Reason is the character encoding.

Solution :

# Solution 1
1. Configure 'Apache Sling Request Parameter Handling', Set the property 'Default Parameter Encoding'='iso-8859-1'
2. Take care of the character encoding (to UTF-8) through code
queryString = new String(request.getParameter(initialSearchConfig.getQueryStringParamName()).getBytes("iso-8859-1"), "UTF-8");

# Solution 2
1.Configure 'Apache Sling Request Parameter Handling', Set the property 'Default Parameter Encoding'='UTF-8'
2. Igonore the encoding through code
queryString = new String(request.getParameter(initialSearchConfig.getQueryStringParamName()));

Hope this help.