Member Center, the user uses the mailbox to retrieve the password configuration
<!--Member Center action-->
<bean id= "web.member.IndexAction" class= "Com.tch.action.member.IndexAction" scope= "prototype" >
<property name= "Tchmemberservice" ref= "Tchmemberservice" ></property>
<property name= "MailSender" ref= "MailSender" ></property>
</bean>
2.JAVA Send mail class
import java.util.Date;
import javax.mail.internet.MimeMessage;
import Org.springframework.mail.javamail.JavaMailSender;
import Org.springframework.mail.javamail.MimeMessageHelper;
Public class Springmail {
/**
* Send HTML mail
* @param Sender Mail Sender entity
* @param toemail recipient's email address
* @param fromemail Sender's email address
* @param titleemail The title of the message sent
* @param contentemail The content of the message sent
* @throws Exception
*/
Public void sendhtmlmail (javamailsender sender,string toemail,string fromemail,string titleemail,string Contentemail)throws Exception {
MimeMessage msg = Sender.createmimemessage ();
Mimemessagehelper helper = new mimemessagehelper (msg,true, "UTF-8");
Mimemessagehelper helper = new Mimemessagehelper (msg);
Helper.setto (Toemail);
System.out.println (fromemail+ ">>" +toemail);
Helper.setfrom (Fromemail);
Helper.setsubject (Titleemail);
Helper.setsentdate (new Date ());
Helper.settext (Contentemail,true);
Sender.send (msg);
SYSTEM.OUT.PRINTLN ("Send mail successfully!");
}
}
3. Start the test, unsuccessful, the console error message:
Org.springframework.mail.MailAuthenticationException:Authentication failed; Nested exception is javax.mail.AuthenticationFailedException
[15:24:47.678] {http--8080-2$13326029} org.springframework.mail.MailAuthenticationException:Authentication failed ; Nested exception is javax.mail.AuthenticationFailedException
Permission validation failed.
Solution: (I suggest using QQ mailbox here)
If you encounter this exception, should think about your assigned to send a mailbox, there is no open pop3/smtp service, as far as I know, now NetEase has not opened up, QQ Mailbox has, but QQ mailbox in the default state, but also did not open this service, you have to "Mailbox Settings" account " Manually set up the POP3/SMTP service, the other mailbox server, only to try to say it.
4. Continuing the test is still unsuccessful and the error message is as follows:
501 Mail from address must is same as authorization user
Reason:
The main reason is the sending class Helper.setfrom (Fromemail);
Setfrom's mailbox account must be the same as the authentication server's mailbox account. For example, the above case must be helper.setfrom ("123456@qq.com");
WORKAROUND: Set the email address of the site to send the 123456@qq.com
5. Conclusion
It is important that the above configuration depends primarily on the services provided by the POP3/SMTP of the open platform.