Spring JavaMailSenderImpl:在哪里设置charset?

时间:2023-01-12 23:21:20

Where do you define the charset a mail is sent with if you are using a Spring JavaMailSenderImpl?

如果您使用的是Spring JavaMailSenderImpl,那么您在哪里定义了一个邮件发送的字符集?

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.

我们使用Spring JavaMailSenderImpl和我们从Websphere Application Server 6.1获得的邮件会话。奇怪的是,用于发送电子邮件的字符集在使用相同代码的不同系统上是不同的。我正在寻找一种覆盖默认值的方法。

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.

更新:我们不允许更改系统属性。所以我正在寻找一种方法来在代码或部署描述符,webshpere meail会话设置或其他任何内容中指定使用的charset。

1 个解决方案

#1


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:

JavaMailSenderImpl有一个名为javaMailProperties的属性,它是一个Properties对象;你可以在那里传递一个带有mail.mime.charset的Properties对象,所以它只适用于你的JavaMailSenderImpl,而不是系统范围的属性:

<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>

#1


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:

JavaMailSenderImpl有一个名为javaMailProperties的属性,它是一个Properties对象;你可以在那里传递一个带有mail.mime.charset的Properties对象,所以它只适用于你的JavaMailSenderImpl,而不是系统范围的属性:

<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>