Reputation: 2753
this is my code for sending a mail to a user.
mailMessage=new SimpleMailMessage();
Strinf passwoed="Abij@1"
String emailHeader = "Dear,";
String emailFooter= "Thanks & Regards ";
mailMessage.setFrom("[email protected]");
mailMessage.setTo("[email protected]");
mailMessage.setSubject("Email For Password");
mailMessage.setText(emailHeader + " \n EMAIL: " + this.newUserModel.getEmailId()+ "\n PASSWORD : " + passWord+ "\n " + emailFooter );
try {
mailSender.send(mailMessage);
}
catch (Exception e) {
logger.info("exception is :"+e.getMessage());
}
When i am running this code i got a exception is :null message..
Upvotes: 0
Views: 464
Reputation: 2753
Solve my problem thanks all of you...
I added the following code in my applicationcontext.xml as per sams..and my code running very well.
Following is my code...
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host">
<value>203.90.70.245(here is the host name)</value>
</property>
<property name="protocol">
<value>smtp</value>
</property>
<property name="port">
<value>2525</value>
</property>
<property name="username">
<value>[email protected](eamil id from you want to send)</value>
</property>
<property name="password">
<value>1234(password of your email id)</value>
</property>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.transport.protocol">smtp</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtp.host">203.90.70.245</prop>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.from">[email protected]</prop>
</props>
</property>
</bean>
and remove from the code mailMessage.setFrom("[email protected]");
And written this code in serviceLayer.
Upvotes: 0
Reputation: 1144
As Per You Ask on SO:-When i am running this code i got a exception is :null message
Just Configure a bean file i.e one xml file.
<bean id="mailID" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="put host server name that u want to use" />
<property name="port" value="port_No" />
<property name="username" value="u_name" />
<property name="password" value="u_pwd" />
<property name="properties_name">
<props>
//define Ur key Here
</props>
</property>
</bean>
<bean id="myMailID" class="Ur Main Class Name following the packageName">
<property name="prop_Name" ref="mailSender" />
</bean>
Here is a good Tut
Upvotes: 2