After the spring consolidation JavaMail succeeded, a large amount of code was configured into the spring configuration file, reducing the JavaMail to mailboxes, ports, protocols, topics, content ... The coupling. You can send a message only if you need to invoke one line of code on the client.
First, you don't have to import jars into the project's lib, but you need to import 3 jar file Activation.jar in Tomcat's Lib, Jspsmartupload.jar,mail.jar import the 3 jar files so Tomcat doesn't have an error.
Sendmanagerservice. java
package com.cgt.itspiderman.service.email;
public interface SendManagerService {
public void sendMail(String email);
}
Defines an interface for sending mail.
Sendmanagerserviceimp.java
Package com.cgt.itspiderman.service.email;
Import Javax.mail.Message;
Import javax.mail.internet.InternetAddress;
Import Javax.mail.internet.MimeMessage;
Import org.springframework.mail.SimpleMailMessage;
Import Org.springframework.mail.javamail.JavaMailSender;
Import Org.springframework.mail.javamail.MimeMessagePreparator;
public class Sendmanagerserviceimp implements Sendmanagerservice {
Private javamailsender Mailsende R
Private simplemailmessage message;
public void SendMail (final String email) {
//TODO auto-generated method stub
Mimeme Ssagepreparator preparator = new Mimemessagepreparator ()
{
public void prepare (MimeMessage Mim Emessage) throws Exception {
mimemessage.setrecipient (Message.RecipientType.TO, New internetaddr ESS (email));
Mimemessage.setfrom (New INternetaddress (Message.getfrom ()));
Mimemessage.setsubject (Message.getsubject (), "GBK");
Mimemessage.settext (Message.gettext (), "GBK");
}
};
Mailsender.send (preparator);
}
Public Javamailsender Getmailsender () {
return mailsender;
public void Setmailsender (Javamailsender mailsender) {
This.mailsender = MailSender;
Public Simplemailmessage getMessage () {
return message;
public void Setmessage (Simplemailmessage message) {
This.message = message;
}
}