Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email 如何在SpringMVC中发送越南人编写的邮件?_Email_Spring Mvc_Utf 8_Send - Fatal编程技术网

Email 如何在SpringMVC中发送越南人编写的邮件?

Email 如何在SpringMVC中发送越南人编写的邮件?,email,spring-mvc,utf-8,send,Email,Spring Mvc,Utf 8,Send,我想用UTF-8发送邮件,但它不起作用 代码如下: @Controller @RequestMapping("/sendEmail") public class SendEmailController { @Autowired private JavaMailSender mailSender; @RequestMapping(method = RequestMethod.POST) public String doSendEmail(HttpServletRequest r

我想用UTF-8发送邮件,但它不起作用

代码如下:

@Controller
@RequestMapping("/sendEmail")
public class SendEmailController {

  @Autowired
  private JavaMailSender mailSender;

  @RequestMapping(method = RequestMethod.POST)
  public String doSendEmail(HttpServletRequest request) {
      // takes input from e-mail form
      final String recipientAddress = request.getParameter("recipient");

      final String subject = request.getParameter("subject");

      final String message = request.getParameter("message");


      // prints debug info
      System.out.println("To: " + recipientAddress);
      System.out.println("Subject: " + subject);
      System.out.println("Message: " + message);


      mailSender.send(new MimeMessagePreparator() {

        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
        MimeMessageHelper messageHelper = new MimeMessageHelper(
        mimeMessage, true, "UTF-8");
        messageHelper.setTo(recipientAddress);
        messageHelper.setSubject(subject);
        //messageHelper.setText(message);
        mimeMessage.setContent(message, "text/html;charset=UTF-8");
        }
      });



      // forwards to the view named "Result"
      return "Result";
  }

}
我将此bean用于:

<bean id="mailSender"
    class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="smtp.gmail.com" />
    <property name="port" value="465" />
    <property name="username" value="khanghuynh92@gmail.com" />
    <property name="password" value="secret" />
    <property name="defaultEncoding" value="UTF-8"/>
    <property name="javaMailProperties">
    <props>
    <prop key="mail.smtp.auth">true</prop>
    <prop key="mail.smtp.socketFactory.class">
    javax.net.ssl.SSLSocketFactory</prop>
    <prop key="mail.smtp.socketFactory.port">465</prop>
    <prop key="mail.debug">true</prop>
    <prop key="mail.smtp.starttls.enable">true</prop>
    </props>
    </property>
</bean>

真的
javax.net.ssl.SSLSocketFactory
465
真的
真的
因此,我在谷歌邮件上得到了以下消息:TÃ''I lÃngÆ°I Viá»T Nam

我能转换成越南语吗


提前感谢您,Khang

您没有说文本应该说什么,但我假设消息是正确的越南语字符,这些字符是使用
消息
参数中的web表单发布的

问题很可能是web表单是使用本地字符集而不是UTF-8发布的

使用UTF-8将表单设置为POST,包括:

<form accept-charset="UTF-8" ... >


你已经公开了你的gmail密码!我已经从你的帖子中删除了密码,但是如果你还没有怀疑你的数据已经“损坏”的话,你应该修改它,甚至在你创建电子邮件之前。您可以通过使用UTF-8编码将消息写入文件来证明这一点。另外,您能描述一下您的J2EE服务器设置以及您正在做什么来发布数据吗?