Announcement Announcement Module
Collapse
No announcement yet.
Null session in JavaMailSenderImpl Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Null session in JavaMailSenderImpl

    I have a problem using JavaMailSenderImpl. When i try to send an email from a standalone class (main or junit) i get a null pointer

    java.lang.NullPointerException
    at org.springframework.mail.javamail.JavaMailSenderIm pl.getTransport(JavaMailSenderImpl.java:412)

    at org.springframework.mail.javamail.JavaMailSenderIm pl.doSend(JavaMailSenderImpl.java:372)
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:291)
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:277)
    at com.todo1.bole2.services.base.notification.SendSin gleMailTest.testSendEmail(SendSingleMailTest.java: 25)


    but if i run a similar code under the app server (sun 7), it runs fine... it actually sends the email.

    The test sample is:

    public void testSendEmail() throws Exception {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost("mail.mycompany.com");
    //
    SimpleMailMessage mailmessagetext = new SimpleMailMessage();
    mailmessagetext.setTo("[email protected]");
    mailmessagetext.setFrom("[email protected]");
    mailmessagetext.setSubject("TEXT test");
    mailmessagetext.setText("Test text");
    mailSender.send(mailmessagetext);


    Any idea why this happens?

  • #2
    Check your mapping. If your junit is coming from a different machine adding this:
    Code:
    <property name="javaMailProperties">
        <props>
          <prop key="mail.smtp.auth">true</prop>
       </props>
    </property>
    may help.

    Steve O

    Comment


    • #3
      Actually the problem is not in Spring but JavaMail, for some reason this 2 calls in JavaMailSenderImpl always return null

      private Session session = Session.getInstance(new Properties());

      public void setJavaMailProperties(Properties javaMailProperties) {
      this.session = Session.getInstance(javaMailProperties);
      }

      I'm still researching why, i must be missing a property or something in the classpath. If you have any clue please let me know.

      Thanks

      Comment


      • #4
        Answer

        Hi there,

        Did you find the answer to the null problem?

        Comment

        Working...
        X