Announcement Announcement Module
No announcement yet.
Relay issue for email and JavamailSenderImpl attributes Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Relay issue for email and JavamailSenderImpl attributes

    I'm currently working on a project where there is an SMTP server that has relaying off so the need arises to set certain session properties. We are using Weblogic 8.1 as the application server, however in setting its mail session properties via the console, according to the documentation, there is only an explicit list which can be set and that list does not include all the properties I need.

    We are also using JNDI vis a vi Spring's JNDIFactory object and injecting that into the session property of the bean that sends mail that uses the class JavamailSenderImpl.

    The problem is that there is no way to explicitly set the field 'mail.smtp.auth' to true or mail.smtp.auth.(user/password ) via spring (using JavamailSenderImpl) or in the weblogic console. The only way I've seen around this is to explicity set the properties for a session by props.put("mail.smtp.auth","true) and then get an instance of the session by calling Session.getInstance(newProperties).

    Is there any way to do this in spring, be it a dependency injection I am unaware of or any other manner??


  • #2
    Relay issue for email and JavamailSenderImpl attributes

    I think the issue is that JavaMailSenderImpl either let's you use a pre-defined session or define properties for your own session, but it does not let you add or override properties to a pre-defined session. Because JavaMailSenderImpl does not declare it's methods final, you can extend JavaMailSenderImpl to allow users to override or add properties to an existing java mail session.

    public class MyJavaMailSenderImpl extends JavaMailSenderImpl implements InitializingBean {
    	private Properties javaMailProperties;
    	/* (non-Javadoc)
    	 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
    	public void afterPropertiesSet() throws Exception {
    		if (javaMailProperties!=null && getSession()!=null) {
    			Properties properties = getSession().getProperties();
    		if (javaMailProperties!=null) {
    	public void setJavaMailProperties(Properties javaMailProperties) {
    		this.javaMailProperties = javaMailProperties;
    The code above checks to see if both javaMailProperties and session have been set. If they are set, we add the javaMailProperties to the existing session properties. Because this seems like a limitation on the original JavaMailSenderImpl, in the long term, I think it makes sense to apply these changes to JavaMailSenderImpl. Thoughts?