Hi all,
I have a requirement to implement a mail sender in our application. Being a fan of Spring framework, i wanted to use the mail sender provided by Spring. Well actually, i started with the small example provided in the documents and i was able to configure and test for its working in my personal system with my gmail account.
But, i'm not able to do the same in my office network and my official mail id's. I could only say that we have a firewall at my office. I couldn't find any other difference
so do we need to add any other configuration to by-pass the firewall? any help would be great. I appreciate the same. anyways, here is the configuration that i'm trying,
and here is my implementation,Code:<!-- Configuration for mail Manager - START --> <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="myhost" /> <property name="port" value="25" /> <property name="protocol" value="smtp" /> <property name="username" value="username" /> <property name="password" value="password" /> <property name="javaMailProperties"> <props> <prop key="mail.smtp.auth">true</prop> <prop key="mail.smtp.starttls.enable">true</prop> <prop key="mail.smtp.ssl.enable">true</prop> </props> </property> </bean> <!-- this is a template message that we can pre-load with default state --> <bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="Paary" /> <property name="subject" value="Test Email" /> <property name="to" value="paary@abc.com" /> <property name="cc" value="manoj@abc.com" /> </bean> <bean id="mailManager" class="com.mail.test.MailManagerTest"> <property name="mailSender" ref="mailSender" /> <property name="templateMessage" ref="templateMessage" /> </bean> <!-- Configuration for mail Manager - END -->
I'm getting NPECode:public class MailManagerTest { private MailSender mailSender; private SimpleMailMessage templateMessage; public void setMailSender(MailSender mailSender) { this.mailSender = mailSender; } public void setTemplateMessage(SimpleMailMessage templateMessage) { this.templateMessage = templateMessage; } public SimpleMailMessage getTemplateMessage() { return templateMessage; } public static void main(String args[]){ System.out.println("MailManager Start"); MailManagerTest mailTest=new MailManagerTest(); System.out.println("Calling the sendEmail()"); mailTest.SendEmail(); System.out.println("MailManager End"); } public void SendEmail(){ ApplicationContext context=new ClassPathXmlApplicationContext("springconfig.xml"); MailManagerTest mailManager=(MailManagerTest) context.getBean("mailManager"); SimpleMailMessage mailMessage=new SimpleMailMessage(mailManager.getTemplateMessage()); mailMessage.setText("This is a test email.Please igmore."); System.out.println(mailMessage); try{ mailSender.send(mailMessage); } catch(MailException me){ System.out.println("Cannot send email"); System.out.println(me); } catch (Exception e) { System.out.println("could not send email"); System.out.println(e.getMessage()); e.printStackTrace(); } } }
This is the stack trace that i got in console,
java.lang.NullPointerException
at com.mail.test.MailManagerTest.SendEmail(MailManage rTest.java:42)
at com.mail.test.MailManagerTest.main(MailManagerTest .java:29)




Reply With Quote
i don't know how i overlooked it! the NPE exception is gone and I'm getting some other exception (something not related to Spring) "Initial Access check failure". I will work on it. 