Java Code Examples for org.apache.commons.mail.SimpleEmail#setMsg()

The following examples show how to use org.apache.commons.mail.SimpleEmail#setMsg() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MailUtil.java    From shop with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 发送邮件给指定人,需要主题和内容
 * @param user
 * @param title
 * @param content
 */
public static void sendMail(String user, String title, String content) {
    SimpleEmail email = new SimpleEmail();
    email.setCharset("UTF8");
    email.setHostName("smtp.163.com");
    email.setAuthentication(USERNAME, PASSWORD);
    try {
        email.setFrom(USERNAME);
        email.addTo(user);
        email.setSubject(title);
        email.setMsg(content);
        email.send();
    } catch (EmailException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: SendEmail.java    From sAINT with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void sendSimpleEmail(String email_to, String subject, String msg) {
    SimpleEmail email = new SimpleEmail();
    try {
        email.setDebug(debug);
        email.setHostName(smtp);
        email.addTo(email_to);
        email.setFrom(email_from);
        email.setAuthentication(email_from, email_password);
        email.setSubject(subject);
        email.setMsg(msg);
        email.setSSL(ssl);
        email.setTLS(tls);
        email.send();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }
}
 
Example 3
Source File: EmailManager.java    From gameserver with Apache License 2.0 6 votes vote down vote up
/**
 * Send a verification email to the user's email account if exist.
 * 
 * @param user
 */
public void sendNormalEmail(String subject, String content, String[] addresses ) {
	if ( StringUtil.checkNotEmpty(subject) && StringUtil.checkNotEmpty(content) ) {
		try {
			String emailSmtp = GameDataManager.getInstance().getGameDataAsString(GameDataKey.EMAIL_SMTP, "mail.xinqihd.com");
			SimpleEmail email = new SimpleEmail();
			email.setHostName(emailSmtp);
			email.setAuthenticator(new DefaultAuthenticator(EMAIL_FROM, "xinqi@2012"));
			email.setFrom(EMAIL_FROM);
			email.setSubject(subject);
			email.setMsg(content);
			email.setCharset("GBK");
			for ( String address : addresses) {
				if ( StringUtil.checkNotEmpty(address) ) {
					email.addTo(address);
				}
			}
			email.send();
		} catch (EmailException e) {
			logger.debug("Failed to send normal email", e);
		}
	}
}
 
Example 4
Source File: EmailUtil.java    From SpringMVC-Project with MIT License 5 votes vote down vote up
/**
 * 发送文本邮件
 */
public static void sendTextEmail(Authenticator authenticator, String hostName, Tuple2<String, String> fromInfo, List<Tuple2<String, String>> toList, List<Tuple2<String, String>> ccList, String subject, String textContent) throws EmailException {
    SimpleEmail simpleEmail = buildSimpleEmail(authenticator, hostName, fromInfo, toList, ccList, subject);
    simpleEmail.setMsg(textContent);

    simpleEmail.send();
}
 
Example 5
Source File: MailActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected SimpleEmail createTextOnlyEmail(String text) {
  SimpleEmail email = new SimpleEmail();
  try {
    email.setMsg(text);
    return email;
  } catch (EmailException e) {
    throw new ActivitiException("Could not create text-only email", e);
  }
}
 
Example 6
Source File: MailActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected SimpleEmail createTextOnlyEmail(String text) {
  SimpleEmail email = new SimpleEmail();
  try {
    email.setMsg(text);
    return email;
  } catch (EmailException e) {
    throw new ActivitiException("Could not create text-only email", e);
  }
}
 
Example 7
Source File: MailActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected SimpleEmail createTextOnlyEmail(String text) {
    SimpleEmail email = new SimpleEmail();
    try {
        email.setMsg(text);
        return email;
    } catch (EmailException e) {
        throw new FlowableException("Could not create text-only email", e);
    }
}
 
Example 8
Source File: MailActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected SimpleEmail createTextOnlyEmail(String text) {
    SimpleEmail email = new SimpleEmail();
    try {
        email.setMsg(text);
        return email;
    } catch (EmailException e) {
        throw new FlowableException("Could not create text-only email", e);
    }
}
 
Example 9
Source File: MailActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected SimpleEmail createTextOnlyEmail(String text) {
    SimpleEmail email = new SimpleEmail();
    try {
        email.setMsg(text);
        return email;
    } catch (EmailException e) {
        throw new ActivitiException("Could not create text-only email", e);
    }
}
 
Example 10
Source File: Main.java    From openseedbox with GNU General Public License v3.0 5 votes vote down vote up
public static void testEmail() {
	try {
		SimpleEmail se = new SimpleEmail();
		se.setFrom("[email protected]");
		se.addTo("[email protected]");
		se.setSubject("Test email from myseedbox");
		se.setMsg("Testy Testy test");
		Mail.send(se);
	} catch (EmailException ex) {
		resultError(ex.toString());
	}
	result("Yay!");
}
 
Example 11
Source File: MailActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected SimpleEmail createTextOnlyEmail(String text) {
  SimpleEmail email = new SimpleEmail();
  try {
    email.setMsg(text);
    return email;
  } catch (EmailException e) {
    throw LOG.emailCreationException("text-only", e);
  }
}
 
Example 12
Source File: SendEmaiWithGmail.java    From spring-boot with Apache License 2.0 4 votes vote down vote up
/**
 * 用 commons 发送简单邮件 用 [email protected] (登录密码为 pass)发送邮件
 * 
 * @author jianghui
 * @param userName
 *            gmail 用户名 test
 * @param password
 *            gmail 密码 pass
 * @param subject
 *            邮件标题
 * @param simpleEmailBody
 *            邮件内容
 * @param from
 *            邮件显示的发信人.实际的发信地址为 gamil 邮箱地址
 * @param to
 *            收件人邮件地址
 * @param cc
 *            抄送人邮件地址,多个地址用分号";"隔开,如果没有,则为空字符串""
 * @param bcc
 *            密送人邮件地址,多个地址用分号";"隔开,如果没有,则为空字符串""
 * @throws EmailException
 */
public void sendsimpleEmail(String userName, String password,
		String subject, String simpleEmailBody, String from, String to,
		String cc, String bcc) throws EmailException {

	// 创建SimpleEmail对象
	SimpleEmail email = new SimpleEmail();

	// 显示调试信息用于IED中输出
	email.setDebug(true);

	// 设置发送电子邮件的邮件服务器
	email.setHostName("smtp.gmail.com");

	// 邮件服务器是否使用ssl加密方式gmail就是,163就不是)
	email.setSSL(Boolean.TRUE);

	// 设置smtp端口号(需要查看邮件服务器的说明ssl加密之后端口号是不一样的)
	email.setSmtpPort(465);

	// 设置发送人的账号/密码
	email.setAuthentication(userName, password);

	// 显示的发信人地址,实际地址为gmail的地址
	email.setFrom(from);
	// 设置发件人的地址/称呼
	// email.setFrom("[email protected]", "发送人");

	// 收信人地址
	email.addTo(to);
	// 设置收件人的账号/称呼)
	// email.addTo("[email protected]", "收件人");

	// 多个抄送地址
	StrTokenizer stokenCC = new StrTokenizer(cc.trim(), ";");
	// 开始逐个抄送地址
	for (int i = 0; i < stokenCC.getTokenArray().length; i++) {
		email.addCc((String) stokenCC.getTokenArray()[i]);
	}

	// 多个密送送地址
	StrTokenizer stokenBCC = new StrTokenizer(bcc.trim(), ";");
	// 开始逐个抄送地址
	for (int i = 0; i < stokenBCC.getTokenArray().length; i++) {
		email.addBcc((String) stokenBCC.getTokenArray()[i]);
	}

	// Set the charset of the message.
	email.setCharset("UTF-8");

	email.setSentDate(new Date());

	// 设置标题,但是不能设置编码,commons 邮件的缺陷
	email.setSubject(subject);

	// 设置邮件正文
	email.setMsg(simpleEmailBody);

	// 就是send发送
	email.send();

	// 这个是我自己写的。
	System.out.println("The SimpleEmail send sucessful!");

}