Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. java.lang.NullPointerException
  2. com.hope.mobilehope.common.Messsageservice.sendMail(Messsageservice.java:26)
  3. com.hope.mobilehope.controller.Authcodegen.getactivationkey(Authcodegen.java:28)
  4. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  5. sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  6. sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  7. below is my sample code
  8.  
  9.  
  10.  
  11.  
  12. @Service("messsageservice")
  13. public class Messsageservice {
  14. @Autowired
  15. private MailSender mailSender;
  16. /*@Autowired
  17. private MailSender mailSender;
  18. */
  19. @RequestMapping(method = RequestMethod.POST)
  20. public void sendMail(String from, String to, String subject, String body) {
  21.  
  22. SimpleMailMessage message = new SimpleMailMessage();
  23.  
  24. message.setFrom(from);
  25. message.setTo(to);
  26. message.setSubject(subject);
  27. message.setText(body);
  28. mailSender.send(message);
  29.  
  30. }
  31.  
  32.  
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. @RestController
  42. public class Authcodegen {
  43. Messsageservice msgservice=new Messsageservice();
  44. @RequestMapping(value = "/activationkeygenerator", method = RequestMethod.GET,headers="Accept=application/json")
  45. public Authcode getactivationkey( @RequestParam(value="email") String name){
  46. Authcode authcode = new Authcode();
  47. Random rnd = new Random();
  48. String to_email=name;
  49. int n = 100000 + rnd.nextInt(900000);
  50. String code=String.valueOf(n);
  51. msgservice.sendMail("ethonnoreply@gmail.com", to_email, "authcode", code);
  52. authcode.setId(n);
  53. authcode.setStatus("Sucess");
  54. return authcode;
  55.  
  56. }
  57.  
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. xml file
  70. <beans xmlns="http://www.springframework.org/schema/beans"
  71. xmlns:context="http://www.springframework.org/schema/context"
  72. xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  73. 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
  74. 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">
  75.  
  76. <mvc:annotation-driven/>
  77. <context:component-scan base-package="com.hope.mobilehope.controller" />
  78.  
  79. <context:component-scan base-package="com.hope.mobilehope.common"/>
  80.  
  81.  
  82.  
  83. <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
  84. <property name="host" value="smtp.gmail.com"/>
  85. <property name="port" value="587"/>
  86. <property name="username" value="ethonnoreply@gmail.com"/>
  87. <property name="password" value="ethon123"/>
  88. <property name="javaMailProperties">
  89. <props>
  90. <!-- Use SMTP transport protocol -->
  91. <prop key="mail.transport.protocol">smtp</prop>
  92. <!-- Use SMTP-AUTH to authenticate to SMTP server -->
  93. <prop key="mail.smtp.auth">true</prop>
  94. <!-- Use TLS to encrypt communication with SMTP server -->
  95. <prop key="mail.smtp.starttls.enable">true</prop>
  96. <prop key="mail.debug">true</prop>
  97. </props>
  98. </property>
  99. </bean>
  100.  
  101.  
  102. </beans>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement