import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
JavaMailSenderImpl senderimpl = new JavaMailSenderImpl();
Properties properties = new Properties();
properties.setProperty("mail.smtp.auth", "true");
senderimpl.setJavaMailProperties(properties);
// 设定mail server
senderimpl.setHost("smtp.163.com");
//设置用户名和密码
senderimpl.setUsername("jctliu");
senderimpl.setPassword("liu3778658");
//建立邮件消息
MimeMessage mimeMessage = senderimpl.createMimeMessage();
MimeMessageHelper messagehelper;
try {
messagehelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
//设置寄件人
messagehelper.setFrom("[email protected]");
//设置收件人
messagehelper.setTo("[email protected]");
//设置邮件主题
messagehelper.setSubject("Test HTML");
//true 表示启动HTML格式的邮件
messagehelper.setText("<html><head></head><body>刘全锋你是最棒的! </body></html>",true);
} catch (MessagingException e) {e.printStackTrace();}
//发送邮件
senderimpl.send(mimeMessage);
}
}