Spring JavaMailSenderImpl:在哪里设置字符集? [英] Spring JavaMailSenderImpl: where to set the charset?
问题描述
如果您使用的是Spring JavaMailSenderImpl,那么在哪里定义与邮件一起发送的字符集?
Where do you define the charset a mail is sent with if you are using a Spring JavaMailSenderImpl?
我们正在将Spring JavaMailSenderImpl与从Websphere Application Server 6.1获得的邮件会话一起使用.奇怪的是,在使用相同代码的不同系统上,用于发送电子邮件的字符集是不同的.我正在寻找一种替代默认设置的方法.
We are using the Spring JavaMailSenderImpl with a mail session we get from the Websphere Application Server 6.1. Strangely, the charsets used in sending the emails are different on different systems using the same code. I am looking for a way to override the default.
更新:我们不允许更改系统属性.因此,我正在寻找一种在代码或部署描述符,webshpere meail会话设置等中指定使用的字符集的方法.
UPDATE: Changing system properties is not allowed for us. So I am looking for a way to specify the used charset in the code or in the deployment descriptors, webshpere meail session settings or whatever.
推荐答案
JavaMailSenderImpl具有一个名为javaMailProperties的属性,它是一个Properties对象.您可以在那里传递带有mail.mime.charset的Properties对象,所以它仅用于JavaMailSenderImpl,而不是系统范围的属性:
JavaMailSenderImpl has a property called javaMailProperties which is a Properties object; you can pass a Properties object with the mail.mime.charset there, so it's just for your JavaMailSenderImpl, not a system wide property:
<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="bla" />
<property name="username" value="user" />
<property name="password" value="pass" />
<property name="javaMailProperties"><props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.connectiontimeout">5000</prop>
<prop key="mail.smtp.sendpartial">true</prop>
<prop key="mail.smtp.userset">true</prop>
<prop key="mail.mime.charset">ISO-8859-1</prop>
</props></property>
</bean>
这篇关于Spring JavaMailSenderImpl:在哪里设置字符集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!