依赖的库 写道
spring-2.5.4.jar
mail-1.4.jar
log4j-1.2.12.jar
commons-logging-1.0.4.jar
activation-1.1.jar
mail-1.4.jar
log4j-1.2.12.jar
commons-logging-1.0.4.jar
activation-1.1.jar
代码
package mail;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
public class MailSender {
public static void main(String[] args) throws Exception {
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
// 设定 Mail Server
senderImpl.setHost("172.16.60.72");
// 建立邮件讯息
SimpleMailMessage mailMessage = new SimpleMailMessage();
// 设定收件人、寄件人、主题与内文
mailMessage.setTo("kejin.lukj@alibaba-inc.com");
mailMessage.setFrom("kejinlu@gmail.com");
mailMessage.setSubject("Test");
mailMessage.setText("This is a test!!!");
// 传送邮件
senderImpl.send(mailMessage);
System.out.println("Mail Sended!");
}
}