Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- java.lang.NullPointerException
- com.hope.mobilehope.common.Messsageservice.sendMail(Messsageservice.java:26)
- com.hope.mobilehope.controller.Authcodegen.getactivationkey(Authcodegen.java:28)
- sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- below is my sample code
- @Service("messsageservice")
- public class Messsageservice {
- @Autowired
- private MailSender mailSender;
- /*@Autowired
- private MailSender mailSender;
- */
- @RequestMapping(method = RequestMethod.POST)
- public void sendMail(String from, String to, String subject, String body) {
- SimpleMailMessage message = new SimpleMailMessage();
- message.setFrom(from);
- message.setTo(to);
- message.setSubject(subject);
- message.setText(body);
- mailSender.send(message);
- }
- }
- @RestController
- public class Authcodegen {
- Messsageservice msgservice=new Messsageservice();
- @RequestMapping(value = "/activationkeygenerator", method = RequestMethod.GET,headers="Accept=application/json")
- public Authcode getactivationkey( @RequestParam(value="email") String name){
- Authcode authcode = new Authcode();
- Random rnd = new Random();
- String to_email=name;
- int n = 100000 + rnd.nextInt(900000);
- String code=String.valueOf(n);
- msgservice.sendMail("ethonnoreply@gmail.com", to_email, "authcode", code);
- authcode.setId(n);
- authcode.setStatus("Sucess");
- return authcode;
- }
- }
- xml file
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
- <mvc:annotation-driven/>
- <context:component-scan base-package="com.hope.mobilehope.controller" />
- <context:component-scan base-package="com.hope.mobilehope.common"/>
- <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
- <property name="host" value="smtp.gmail.com"/>
- <property name="port" value="587"/>
- <property name="username" value="ethonnoreply@gmail.com"/>
- <property name="password" value="ethon123"/>
- <property name="javaMailProperties">
- <props>
- <!-- Use SMTP transport protocol -->
- <prop key="mail.transport.protocol">smtp</prop>
- <!-- Use SMTP-AUTH to authenticate to SMTP server -->
- <prop key="mail.smtp.auth">true</prop>
- <!-- Use TLS to encrypt communication with SMTP server -->
- <prop key="mail.smtp.starttls.enable">true</prop>
- <prop key="mail.debug">true</prop>
- </props>
- </property>
- </bean>
- </beans>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement