Public StaticvoidSendEmail ()throwsException {Javamailsenderimpl Senderimpl=NewJavamailsenderimpl (); //setting up mail serverSenderimpl.sethost ("smtp.163.com"); //Create a mail message to send the difference between a simple message and an HTML messageMimeMessage MailMessage =Senderimpl.createmimemessage (); Mimemessagehelper Messagehelper=NewMimemessagehelper (MailMessage, "Utf-8"); //set recipient, senderMessagehelper.setto ("[Email protected]"); Messagehelper.setfrom ("[Email protected]"); Messagehelper.setsubject ("Test HTML mail!" "); //true to start HTML-formatted messagesMessagehelper.settext ("true); Senderimpl.setusername ("username");//Depending on your situation, set the usernameSenderimpl.setpassword ("password");//Depending on your situation, set the passwordProperties prop =NewProperties (); Prop.put ("Mail.smtp.auth", "true");//set this parameter to TRUE to have the server authenticate and authenticate the user name and password correctlyProp.put ("Mail.smtp.timeout", "25000"); Senderimpl.setjavamailproperties (prop); //Send mailsenderimpl.send (MailMessage); System.out.println ("Message sent successfully ..."); }
Problem:
When I test to send the message, only when the method is changed to static to send the success, otherwise reported:Request processing failed; nested exception is Java.lang.NullPointerExceptio. What is this for? Does anyone know?
Spring Send mail problem