Announcement Announcement Module
Collapse
No announcement yet.
overriding SimpleMailMessage template config? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • overriding SimpleMailMessage template config?

    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="[email protected]"/>
          <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="[email protected]"/>
          <property name="to" value="[email protected]"/>
        </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?
    Last edited by keiko; Jan 3rd, 2008, 01:03 AM.

  • #2
    That's a limitation of Gmail's SMTP server. It always rewrite the sender's email with the email used to authenticate. Gmail isnt a totally open SMTP relay. For that, you should probably use your ISP's server.

    Comment


    • #3
      Oh, darn. Really? That sucks. So even if I subscribed my domain to that Google Apps Standard Edition, there's no workaround?

      Oh, well...

      Thanks for pointing it out. I'm glad, my web app is still in its early stages, a bit far from deployment. And I'm more glad it wasn't my coding.

      Comment


      • #4
        I dont know anything about "Google Apps Standard Edition", and domain mail hosting at Google. You might be able to get it working ... But this is a Google problem, nothing wrong with your code ...

        Comment

        Working...
        X