Hybris中sendEmail动作的邮件UTF-8编码设置问题
Hey there! I’ve dealt with this exact UTF-8 encoding hiccup using sendEmail before—super frustrating when everything else works but your special characters (like non-English text) get garbled. Let’s walk through the fixes based on the most common sendEmail tools out there:
Command-Line sendEmail Tool
If you’re using the popular sendEmail command-line utility, you can force UTF-8 encoding with two key parameters:
-o message-charset=UTF-8: Sets the character set for the email body-o content-type=text/html;charset=UTF-8(ortext/plainif you’re sending plain text): Tells email clients to interpret the content as UTF-8
Here’s a full example command that covers both body and subject encoding:
sendEmail \ -f sender@yourdomain.com \ -t recipient@theirdomain.com \ -s smtp.yourdomain.com \ -u "你的UTF-8主题" \ -m "包含中文、特殊字符的邮件内容" \ -o message-charset=UTF-8 \ -o subject-charset=UTF-8 \ -o content-type=text/plain;charset=UTF-8
The subject-charset flag ensures your email subject also uses UTF-8—critical if your subject has non-ASCII characters.
Jenkins sendEmail Plugin
If you’re using Jenkins’ sendEmail plugin, the fix is straightforward in the system config or your pipeline:
- System-Wide Configuration:
- Go to Manage Jenkins > Configure System
- Scroll down to the Extended E-mail Notification section (or the core Email Notification area, depending on your plugin version)
- Find the Default Content Type dropdown—select either
Plain Text (text/plain)orHTML (text/html) - In the adjacent Character Set field, enter
UTF-8
- Pipeline Step:
If you’re defining the sendEmail action directly in a Jenkinsfile, specify the charset explicitly:sendEmail( to: 'recipient@theirdomain.com', subject: 'UTF-8 主题', body: '带有特殊字符的邮件正文', mimeType: 'text/plain', charset: 'UTF-8' )
General Tip for Other Platforms
If you’re using sendEmail in a different tool (like a custom script or low-code platform), look for options to add custom email headers. Manually include this header to enforce UTF-8:
Content-Type: text/plain; charset=UTF-8
Or for HTML emails:
Content-Type: text/html; charset=UTF-8
This tells mail clients exactly how to decode your content, so special characters display correctly.
内容的提问来源于stack exchange,提问作者Hector Gonzalez Santiago

