Spring Send mail problem

Source: Internet
Author: User

  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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.