Announcement Announcement Module
Collapse
No announcement yet.
Spring Mail Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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("[email protected]") ;
    mailSender.send(message) ;
    }

    What am I doing wrong?

    Thanks.

  • #2
    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

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment


          • #6
            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.

            Comment

            Working...
            X