class EmailUtil {

	public static boolean send(String receiverName, String receiverAccount, String subject, String content) {
		Properties props = System.getProperties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.smtp.host", SENDER_SMTP_HOST);
		props.setProperty("mail.smtp.auth", "true");

		Session session = Session.getDefaultInstance(props);
		// 设置为debug模式, 可以查看详细的发送log
		session.setDebug(DEBUG);

		Transport transport = null;
		try {
			MimeMessage message = createMimeMessage(session, receiverName, receiverAccount, subject, content);
			transport = session.getTransport();
			transport.connect(SENDER_ACCOUNT, SENDER_PASSWORD);
			transport.sendMessage(message, message.getAllRecipients());
		} catch (UnsupportedEncodingException | MessagingException e) {
			logger.error(EMAIL_SEND_ERROR, e);
			return false;
		} finally {
			try {
				if (transport != null) {
					transport.close();
				}
			} catch (MessagingException e) {
				logger.error(EMAIL_SEND_ERROR, e);
			}
		}
		return true;
	}

}

class EmailUtilTest {

	@Test
	public void send() throws Exception {

		boolean success = EmailUtil.send("favorisites用户", "1203948298@qq.com",
				"123456是您的favorisites验证码", "<div style=\"text-align: center;color:dodgerblue;\">欢迎注册使用favoristes， 您的验证码是123456</div>");
		System.out.println(success);
	}

}