我使用Javax Mail API发送电子邮件.我使用联系方式发送输入,必须将其发送到特定的电子邮件.
发送电子邮件没有问题,虽然我是一个丹麦人,因此我需要三个丹麦字符,即'æ','ø'和'å',在主题和电子邮件文本中.
因此我看到我可以使用UTF-8字符编码来提供这些字符,但是当我的邮件发送时我只看到一些奇怪的字母 - 'ã|','ã¸'和'ã¥' - 而不是丹麦语字母 - 'æ','ø'和'å'.
我发送电子邮件的方法看起来像这样
public void sendEmail(String name, String fromEmail, String subject, String message) throws AddressException, MessagingException, UnsupportedEncodingException, SendFailedException
{
//Set Mail properties
Properties props = System.getProperties();
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtp.host", "smtp.gmail.com");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("my_username", "my_password");
}
});
//Create the email with variable input
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.setHeader("Content-Type", "text/plain; charset=UTF-8");
mimeMessage.setFrom(new …Run Code Online (Sandbox Code Playgroud)