我写了你可以发送电子邮件的visualforce页面。它在英语中运行良好。但是当我在电子邮件正文部分输入日语并发送时,我的电子邮件收件箱有问号而不是日语。
gmail中的正文全部显示?
??????????????????????????
我想我需要对字符串进行编码?但是如何在 Apex 代码中做到这一点?EncodeUtil 类的方法很少,但它不使用 String 进行编码。
代码
public PageReference sendEmail() {
Messaging.SingleEmailMessage mail = new Messaging.singleEmailMessage();
//subject
subject = 'my subject';
mail.setSubject(subject);
//set sender name
mail.setSenderDisplayName('im sender');
//set recipient
emailTo = 'test@test.com'; //test sample email address
mail.setToAddresses(new String[]{emailTo});
//set body
String bodyText = '送信者'; //add Japanese to body
mail.setPlainTextBody(bodyText);
try{
Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
if(resultMail[0].isSuccess())
response = 'ok sent!';
else{
response = resultMail[0].getErrors().get(0).getMessage();
}
}catch(System.EmailException ex){
response = ex.getMessage();
}
}