Results 1 to 6 of 6

Thread: Spring Mail

  1. #1

    Default Spring Mail

    I am trying to send an email using Spring and GMail. However, the email is not getting sent. I'm not receiving any errors. Below is my setup:

    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailS enderImpl">
    <property name="host" value="smtp.gmail.com"/>
    <property name="port" value="25"/>
    <property name="username" value="MyUsername"/>
    <property name="password" value="MyPassword"/>
    <property name="javaMailProperties">
    <props>
    <prop key="mail.smtp.auth">true</prop>
    <prop key="mail.smtp.starttls.enable">true</prop>
    </props>
    </property>
    </bean>


    <bean id="userDefServiceTarget"
    class="com.xxx.setups.userdef.business.UserDefMgr" >
    <property name="mailSender"><ref local="mailSender"/></property>
    </bean>

    public void postMail()
    {
    SimpleMailMessage message = new SimpleMailMessage() ;
    message.setSentDate(new Date()) ;
    message.setSubject("Test") ;
    message.setText("This is a test email.") ;
    message.setFrom("test@xx.com") ;
    mailSender.send(message) ;
    }

    What am I doing wrong?

    Thanks.

  2. #2
    Join Date
    Mar 2006
    Location
    Bangalore, India
    Posts
    242

    Default

    Hi,

    Try and check if there is connectivity to the smtp server,

    check if you are behind a firewall or a proxy, you would have to configure the proxyHost and proxyPort if needed
    Sami

  3. #3

    Default gmail

    Thanks for the reply, Sami. I try to telnet to smtp.gmail.com 25 and get the following: 220 mx.google.com ESTMP 6sm37606787ywn.7 -- That's all I get. My windows firewall is disabled.

  4. #4
    Join Date
    Oct 2008
    Posts
    136

    Default

    Just a thought: on the same machine, try to connect to GMail using whatever email client is handy using the same settings. If this succeeds, then I would think the next step would be to deduce what is different between the settings in your code and the settings in the client.

    When I get home maybe I will have time to try to hook up to GMail with JavaMail, but I do it a little differently. I use Velocity and templates because I send out merged mail, so I use the following from the Velocity/Spring examples:

    Code:
    protected MimeMessagePreparator prepareMessage (final String emailBody,
        final String toAddress, final String fromAddress) throws MessagingException
        {
            MimeMessagePreparator preparator = new MimeMessagePreparator()
            {
                public void prepare (final MimeMessage mimeMessage)
                                throws MessagingException
                {
                    MimeMessageHelper messageHelper = new MimeMessageHelper(
                                    mimeMessage);
                    messageHelper.setTo(toAddress);
                    messageHelper.setFrom(fromAddress);
                    messageHelper.setSubject(_subject);
                    messageHelper.setText(emailBody, true);
                }
            };
    
            return preparator;
        }
    and

    Code:
    _mailSender.send(prepareMessage(body, toAddress, fromAddress ));
    where _mailSender is a JavaMailSender configured for an internal SMTP server.

    Hope this helps.

  5. #5

    Default Gmail

    Thanks Dude for the reply. I am able to get to gmail thru Outlook. I will dig back in the code and see what is different between the two.

  6. #6
    Join Date
    Oct 2008
    Posts
    136

    Default

    Quote Originally Posted by dorr67 View Post
    Thanks Dude for the reply. I am able to get to gmail thru Outlook. I will dig back in the code and see what is different between the two.
    If you haven't already, you might try a different SMTP server if you have access to one - something with different settings - as another datapoint to help you debug.

Posting Permissions

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