Java Code Examples for org.apache.commons.mail.Email#setCharset()

The following examples show how to use org.apache.commons.mail.Email#setCharset() . 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: NewsletterMailer.java    From mamute with Apache License 2.0 5 votes vote down vote up
public void sendTo(ScrollableResults results, boolean isTestNewsletter) {
	DateTime pastWeek = new DateTime().minusWeeks(1);
	DateTime twelveHoursAgo = new DateTime().minusHours(12);
	List<News> hotNews = news.hotNews();
	List<Question> hotQuestions = questions.hot(pastWeek, 8);
	List<Question> unanswered = questions.randomUnanswered(pastWeek, twelveHoursAgo, 8);
	LinkToHelper linkToHelper = new NotificationMailer.LinkToHelper(router, brutalEnv);
	String siteName = bundle.getMessage("site.name");
	String date = brutalDateFormat.getInstance("date.joda.newsletter.pattern").print(new DateTime());
	
	String teste = isTestNewsletter ? bundle.getMessage("newsletter_mail_test") : "";
	
	while (results.next()) {
		User user = (User) results.get()[0];
		try {
			Email email = templates.template("newsletter_mail", date, siteName, teste)
					.with("hotNews", hotNews)
					.with("hotQuestions", hotQuestions)
					.with("unansweredQuestions", unanswered)
					.with("unsubscribeLink", linkToHelper.unsubscribeLink(user))
					.with("linkToHelper", linkToHelper)
					.with("l10n", bundle)
					.with("sanitizer", POLICY)
					.with("siteName", siteName)
					.with("date", date)
					.with("logoUrl", env.get("mail_logo_url"))
					.to(user.getName(), user.getEmail());
			email.setCharset("utf-8");
			mailer.send(email);
		} catch (Exception e) {
			LOG.error("could not send email", e);
		}
	}

}
 
Example 2
Source File: NotificationMailer.java    From mamute with Apache License 2.0 5 votes vote down vote up
public void send(NotificationMail notificationMail) {
	User to = notificationMail.getTo();
	Email email = buildEmail(notificationMail);
	email.setCharset("utf-8");
	try {
		mailer.send(email);
	} catch (EmailException e) {
		LOG.error("Could not send notifications mail to: " + to.getEmail(), e);
	}
}
 
Example 3
Source File: MailService.java    From Kylin with Apache License 2.0 5 votes vote down vote up
/**
 * @param receivers
 * @param subject
 * @param content
 * @return true or false indicating whether the email was delivered successfully
 * @throws IOException
 */
public boolean sendMail(List<String> receivers, String subject, String content) throws IOException {

    if (!enabled) {
        logger.info("Email service is disabled; this mail will not be delivered: " + subject);
        logger.info("To enable mail service, set 'mail.enabled=true' in kylin.properties");
        return false;
    }

    Email email = new HtmlEmail();
    email.setHostName(host);
    if (username != null && username.trim().length() > 0) {
        email.setAuthentication(username, password);
    }

    //email.setDebug(true);
    try {
        for (String receiver : receivers) {
            email.addTo(receiver);
        }

        email.setFrom(sender);
        email.setSubject(subject);
        email.setCharset("UTF-8");
        ((HtmlEmail) email).setHtmlMsg(content);
        email.send();
        email.getMailSession();

    } catch (EmailException e) {
        logger.error(e.getLocalizedMessage(),e);
        return false;
    }

    return true;
}
 
Example 4
Source File: MailActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void setCharset(Email email, String charSetStr) {
  if (charset != null) {
    email.setCharset(charSetStr);
  }
}
 
Example 5
Source File: MailActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void setCharset(Email email, String charSetStr) {
  if (charset != null) {
    email.setCharset(charSetStr);
  }
}
 
Example 6
Source File: SendEmaiWithGmail.java    From spring-boot with Apache License 2.0 4 votes vote down vote up
public void sendsimpleEmail2(Email email, String userName, String password,
		String subject, String simpleEmailBody, String from, String to,
		String cc, String bcc) throws EmailException {

	// 创建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!");

}
 
Example 7
Source File: MailActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected void setCharset(Email email, String charSetStr) {
    if (charset != null) {
        email.setCharset(charSetStr);
    }
}
 
Example 8
Source File: MailActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected void setCharset(Email email, String charSetStr) {
    if (charset != null) {
        email.setCharset(charSetStr);
    }
}
 
Example 9
Source File: MailActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected void setCharset(Email email, String charSetStr) {
    if (charset != null) {
        email.setCharset(charSetStr);
    }
}
 
Example 10
Source File: MailActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void setCharset(Email email, String charSetStr) {
  if (charset != null) {
    email.setCharset(charSetStr);
  }
}