cancel
Showing results for 
Search instead for 
Did you mean: 

Email subject with non-ASCII characters and uSendSMTPMessage

lambert-giese
Active Participant
0 Kudos

Hello IdM experts,

I'm trying to send an email notification from IdM 7.2 SP7 using JavaScript function uSendSMTPMessage. The email subject line contains German umlauts, e.g. the character 'ü' as part of the word "für". The email is sent without error messages. However, the subject line does not arrive correctly at the email recipient side. For example, character 'ü' is replaced with a pipe character '|'. As a side note: the email body also contains German umlauts; these are transferred without any problems. The issue only exists for the subject line.

I've tried working around this by using different variants of how to specify the actual umlaut in the JavaScript code:

  • as a literal character (i.e. var subject = "Genehmigung für ... erforderlich";)
  • via Unicode escape sequence (i.e. var subject = "Genehmigung f\u00FC ... erforderlich";)

None of these provided the correct end result after the email had been received. The receiver always gets | instead of ü.

Assuming that this problem is related to character set and codepage, I've tried using the optional parameter SubjectCodePage to the uSendSMTPMessage call, which looks exactly like what I need. According to MSDN, the codepage identifier I would need to specify for Western European encoding (i.e. ISO-8859-1) is "28591".

My problem with that approach, however, is that specifying SubjectCodePage, which is the 15th parameter to uSendSMTPMessage, would require that I specify all 14 parameters before that. That's a problem specifically for parameter number 8, Attachment, because I don't want to send any attachment. I tried supplying the parameter with

  • null
  • empty string ("")
  • undefined

but each of these attempts failed with an exception "uSendSMTPMessage: Cannot read attached file."

Two questions here:

  • What's the best approach to deal with non-ASCII characters like German umlauts in email subject?
  • if the SubjectCodePage parameter mentioned above is the solution: how do I use it without attachment, or more generally spoken: what value can I supply to the optional parameters to indicate that they're not relevant?

Best regards,

Lambert

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Lambert,

the charset-issue is depending on the used charset for the current installation.

Most of the Java Installations on Microsoft Windows use CP1252.

You can see this for example when you start the user-interface of the sapjco.jar/sapjco3.jar.

For sending out emails you can just change the encoding of the string itself with JAVA tools from the JVM. JAVA itself is using UTF-16 for strings internally but UTF-8 should be good for international emails including e.g. German and Chinese.

In the Javascript just do the following with your subject-string.

Import a utility-class from the JVM and use it to change the charset.

importClass(Packages.javax.mail.internet.MimeUtility);

var utfsubject = MimeUtility.encodeText(subject, "utf-8", "B");

You can specify to use UTF-8 in the body as well but this is possible with a method parameter.

You can try the following:

UserFunc.uSendSMTPMessage(sender, recipient, utfsubject, body, email_host, "text/html;charset=utf-8", email_port);

In this scenario you wouldn't need to handle the attachment.

Best Regards,

Gunnar

lambert-giese
Active Participant
0 Kudos

Hello Gunnar,

terrific answer, works perfectly.

Thanks & best regards,

Lambert

Answers (0)