Results 1 to 4 of 4

Thread: overriding SimpleMailMessage template config?

  1. #1
    Join Date
    Dec 2007
    Posts
    2

    Default 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="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?
    Last edited by keiko; Jan 3rd, 2008 at 01:03 AM.

  2. #2
    Join Date
    Jul 2005
    Location
    Geneva (Switzerland)
    Posts
    304

    Default

    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.

  3. #3
    Join Date
    Dec 2007
    Posts
    2

    Default

    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.

  4. #4
    Join Date
    Jul 2005
    Location
    Geneva (Switzerland)
    Posts
    304

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •