views:

937

answers:

1

Where do you define the charset a mail is sent with if you are using a 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.

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.

+1  A: 

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