Java邮件编码非英文字符

标签 java email encoding internationalization

使用下面的代码,我可以发送一封非英语的电子邮件,尽管主题显示正确,但正文显示为乱码。
有什么想法吗?
谢谢

public void postMail(String recipient, String subject, String message, String from) throws MessagingException, UnsupportedEncodingException {

            //Set the host smtp address
            Properties props = new Properties();
            props.put("mail.smtp.host", "mail.infodim.gr");

            // create some properties and get the default Session
            Session session = Session.getDefaultInstance(props, null);

            // create a message
            Message msg = new MimeMessage(session);

            // set the from and to address
            InternetAddress addressFrom = new InternetAddress(from);
            msg.setFrom(addressFrom);

            InternetAddress addressTo=new InternetAddress(recipient);
            msg.setRecipient(Message.RecipientType.TO, addressTo);

            // Setting the Subject and Content Type
            msg.setSubject(subject);

            msg.setContent(message, "text/plain");
            Transport.send(msg);

        }

最佳答案

尝试:

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

编辑更改为text/plain

关于Java邮件编码非英文字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2543589/

相关文章:

java - 如何在 EJBClientInterceptor 中管理状态

java - 使用java访问outlook邮件服务器

html - 雅虎!邮件 HTML 电子邮件对齐问题

php - 用对应的口音替换口音

sockets - Flutter/Dart套接字通信,字符编码问题

java - 使用比较器<T>

java - 自定义注解参数化继承其他注解

java - 要么是菜鸟错误,要么是在java中误用.equals

ios - 在iphone中将图像放入邮件正文

c - 在 Windows 控制台上阅读土耳其语字符