I have a web application that includes a form mailer feature wherein a user can enter his email address and his recipients' address as well, which should reflect on the delivered message. It successfully sends messages but my problem is that the sender's email address, instead of displaying my site's domain, always display my Gmail account address, which is only used for authenticating the SMTP.
In applicationContext-mail.xml
PHP Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="emailManager" class="com.xxx.www.service.impl.EmailManagerImpl">
<property name="mailSender" ref="mailSender"/>
<property name="templateMessage" ref="templateMessage"/>
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com"/>
<property name="port" value="465"/>
<property name="protocol" value="smtps"/>
<property name="username" value="my-account@gmail.com"/>
<property name="password" value="xxx"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtps.auth">true</prop>
<prop key="mail.smtps.starttls.enable">true</prop>
<prop key="mail.smtps.debug">true</prop>
</props>
</property>
</bean>
<bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage">
<property name="from" value="server@mysite.com"/>
<property name="to" value="dummy-user@mysite.com"/>
</bean>
</beans>
The specific module in EmailManagerImpl.java
PHP Code:
public void sendReferral(ReferralForm form) {
SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
msg.setFrom(form.getSenderEmail()); // It doesn't seem to override the template >_<
msg.setTo(form.getRecipientEmail()); // But the setTo and the others do...
msg.setSubject(form.getSubject());
msg.setText(form.getMessage());
try{
this.mailSender.send(msg);
} catch(MailException mex) {
System.err.println(mex.getMessage());
}
}
Any ideas, guys?