Results 1 to 3 of 3

Thread: JavaMailSender and Amazon SES doesn't work on JDK1.7

  1. #1
    Join Date
    Jul 2012
    Posts
    3

    Default JavaMailSender and Amazon SES doesn't work on JDK1.7

    Hi,

    I've a EmailService Class like this:
    Code:
    package com.helios.service.mail;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.mail.MessagingException;
    import javax.mail.NoSuchProviderException;
    import javax.mail.internet.AddressException;
    import javax.mail.internet.MimeMessage;
    
    import org.apache.log4j.Logger;
    import org.springframework.stereotype.Service;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.mail.MailException;
    import org.springframework.mail.javamail.MimeMessageHelper;
    import org.springframework.mail.javamail.JavaMailSender;
    
    import scala.actors.threadpool.Arrays;
    import com.helios.util.PropertiesUtil;
    
    /**
     * The e-mail service contains all you need in order to send E-Mails 
     * successfully
     */
    @Service
    public class EmailService
    {
    	// ------------------------------------------------------------------------
    	// members
    	// ------------------------------------------------------------------------
    
    	// log4j...
    	static final Logger logger = Logger.getLogger(EmailService.class);
    	
    	@Autowired
        private JavaMailSender mailSender;
    	
    	// ------------------------------------------------------------------------
    	// public usage
    	// ------------------------------------------------------------------------
    	
    	/**
    	 * Send an Email the cool way!
    	 * @param recipients
    	 * @param subject
    	 * @param text
    	 * @param html
    	 */
    	public void sendEmail(List<String> recipients,String subject,
    			String text,boolean html)
    		throws NoSuchProviderException,AddressException,MessagingException {
    		
    		try {
    			MimeMessage mimeMessage = mailSender.createMimeMessage();
    			MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage);
    			messageHelper.setFrom(PropertiesUtil.getProperty("mail.defaultsender"));
    			messageHelper.setTo(recipients.toArray(new String[recipients.size()]));
    			messageHelper.setSubject(subject);
    			messageHelper.setText(text, html);
    			mailSender.send(mimeMessage);
    		}
    		catch (MailException ex) {
    			logger.error("Fail: "+ex.getMessage());
    		}
    		
    	}
    	// ------------------------------------------------------------------------
    	// private usage
    	// ------------------------------------------------------------------------
    
    	
    	// ------------------------------------------------------------------------
    	// GETTER & SETTER
    	// ------------------------------------------------------------------------
    }
    A bean is used to configure the mailSender to send trough Amazon SES

    Code:
    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="email-smtp.us-east-1.amazonaws.com" />
        <property name="port" value="465" />
        <property name="protocol" value="smtps" />
        <property name="username" value="..." />
        <property name="password" value="..." />
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtps.auth">true</prop>
                <prop key="mail.smtp.ssl.enable">true</prop>
                <prop key="mail.transport.protocol">smtps</prop>
                <prop key="mail.debug">true</prop>
            </props>
        </property>
    </bean>
    Now, if i run the sendEmail method under JDK1.6 it will work fine. If i run absolutly same code on 1.7 it won't work.

    I can't find out where the problem is. Do you have any idea?

    Thanks!

    PS: I'm developing on a Mac OS X (10.8) with the following JDKs:
    Screen Shot 2012-07-28 at 01.20.21.png

  2. #2

    Default

    Any errors in log? Please post if there is any.

  3. #3
    Join Date
    Jul 2012
    Posts
    3

    Default

    Quote Originally Posted by tannoy View Post
    Any errors in log? Please post if there is any.
    Hi,
    There wasn't really an error. The connection was established and then closed due a timeout. The email wasn't sent.
    So I found a solution: I've just upgraded my JDK Version to 1.7.0_05 and it worked again.

Posting Permissions

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