本文整理汇总了Java中org.apache.commons.mail.Email.setCharset方法的典型用法代码示例。如果您正苦于以下问题:Java Email.setCharset方法的具体用法?Java Email.setCharset怎么用?Java Email.setCharset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.mail.Email
的用法示例。
在下文中一共展示了Email.setCharset方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureConnection
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private static void configureConnection(Email email) {
try {
email.setSmtpPort(SMTP_PORT);
email.setHostName(SMTP_HOST);
email.setCharset(CHARSET);
if (!GeneralUtils.isEmpty(SMTP_USER)) {
email.setAuthentication(
SMTP_USER,
SMTP_PASSWORD
);
}
email.setSSLOnConnect(SMTP_SSL);
email.setStartTLSEnabled(SMTP_TLS);
} catch (Throwable ex) {
LOG.error("Erro ao configurar o email.", ex);
throw new RuntimeException("Error configuring smtp connection.", ex);
}
}
示例2: sendMail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
public void sendMail(Mail mail)
throws IOException {
Email email = mail.getMail();
try {
setEncryption(email);
email.setHostName(host);
email.setSmtpPort(port);
email.setCharset("UTF-8");
email.send();
} catch (EmailException e) {
if (Utility.throwableContainsMessageContaining(e, "no object DCH")) {
throw new UnhandledException("\"no object DCH\" Likely cause: the activation jar-file cannot see the mail jar-file. Different ClassLoaders?", e);
} else {
throw new UnhandledException(e);
}
}
}
示例3: sendMail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
public static void sendMail(MailConf mailConf, String mailLine) throws EmailException {
Email email = new SimpleEmail();
email.setHostName(mailConf.getSmtp_server());
email.setSmtpPort(mailConf.getSmtp_port());
email.setAuthenticator(new DefaultAuthenticator(mailConf.getUser_name(), mailConf.getPassword()));
email.setSSLOnConnect(mailConf.isSmtp_ssl_flag());
email.setFrom(mailConf.getSrc_mail_adress());
email.setSubject(Constant.SOFTWARE_NAME + " " + System.currentTimeMillis());
email.setContent(mailLine, "text/plain; charset=ISO-2022-JP");
email.setCharset("ISO-2022-JP");
// try {
// email.setMsg(new String(mailLine.getBytes("iso-2022-jp")));
// } catch (UnsupportedEncodingException e) {
// // TODO 自動生成された catch ブロック
// e.printStackTrace();
// }
email.addTo(mailConf.getDest_mail_adress());
email.send();
}
示例4: send
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
@Override
public void send(String recipient, String subject, String content) throws SendMailException {
Assert.hasText(recipient);
Assert.hasText(subject);
Assert.hasText(content);
Email email = new SimpleEmail();
email.setHostName(host);
email.setAuthenticator(new DefaultAuthenticator(loginName, loginPassword));
email.setSmtpPort(port);
email.setTLS(tls);
try {
email.setCharset("UTF-8"); // specify the charset.
email.setFrom(fromAddress, fromName);
email.setSubject(subject);
email.setMsg(content);
email.addTo(recipient);
email.send();
} catch (EmailException e) {
throw new SendMailException(
String.format("Failed to send mail to %s.", recipient), e);
}
}
示例5: createNewEmail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private static Email createNewEmail(final NotificationProperties properties) throws EmailException {
final Email email = new SimpleEmail();
email.setCharset(Defaults.CHARSET.displayName());
email.setHostName(properties.getSmtpHostname());
email.setSmtpPort(properties.getSmtpPort());
email.setStartTLSRequired(properties.isStartTlsRequired());
email.setSSLOnConnect(properties.isSslOnConnectRequired());
email.setAuthentication(properties.getSmtpUsername(), properties.getSmtpPassword());
final String localhostAddress = LocalhostAddress.INSTANCE.get().orElse("unknown host");
email.setFrom(properties.getSender(), "RoboZonky @ " + localhostAddress);
email.addTo(properties.getRecipient());
return email;
}
示例6: initEmail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private void initEmail(Email email,String fromEmail, String fromPasswd,String fromName,
String host,List<String> toEmailList,MailMsg mailMsg) throws EmailException{
email.setHostName(host);
//邮件服务器验证:用户名/密码
email.setAuthentication(fromEmail, fromPasswd);
//必须放在前面,否则乱码
email.setCharset(MailCfg.CHARSET);
email.setDebug(false);//是否开启调试默认不开启
email.setSSLOnConnect(true);//开启SSL加密
email.setStartTLSEnabled(true);//开启TLS加密
email.addTo(toEmailList.toArray(new String[0]));
email.setFrom(fromEmail,fromName);
email.setSubject(mailMsg.getSubject());
}
示例7: sendSimpleEmail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private void sendSimpleEmail() throws MangooMailerException {
Config config = Application.getInstance(Config.class);
try {
Email email = new SimpleEmail();
email.setCharset(Default.ENCODING.toString());
email.setHostName(config.getSmtpHost());
email.setSmtpPort(config.getSmtpPort());
email.setAuthenticator(getDefaultAuthenticator());
email.setSSLOnConnect(config.isSmtpSSL());
email.setFrom(this.from);
email.setSubject(this.subject);
email.setMsg(render());
for (String recipient : this.recipients) {
email.addTo(recipient);
}
for (String cc : this.ccRecipients) {
email.addCc(cc);
}
for (String bcc : this.bccRecipients) {
email.addBcc(bcc);
}
email.send();
} catch (EmailException | MangooTemplateEngineException e) {
throw new MangooMailerException(e);
}
}
示例8: sendTo
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
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);
}
}
}
示例9: send
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
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);
}
}
示例10: sendMail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
/**
* @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;
}
示例11: sendsimpleEmail2
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
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!");
}
示例12: setCharset
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
protected void setCharset(Email email, String charSetStr) {
if (charset != null) {
email.setCharset(charSetStr);
}
}
示例13: setCharset
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
protected void setCharset(Email email, String charSetStr) {
if (charset != null) {
email.setCharset(charSetStr);
}
}
示例14: sendMail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
/**
* @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, boolean isHtmlMsg) {
if (!enabled) {
logger.info("Email service is disabled; this mail will not be delivered: " + subject);
logger.info("To enable mail service, set 'kylin.job.notification-enabled=true' in kylin.properties");
return false;
}
Email email = new HtmlEmail();
email.setHostName(host);
email.setStartTLSEnabled(starttlsEnabled);
if (starttlsEnabled) {
email.setSslSmtpPort(port);
} else {
email.setSmtpPort(Integer.valueOf(port));
}
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");
if (isHtmlMsg) {
((HtmlEmail) email).setHtmlMsg(content);
} else {
((HtmlEmail) email).setTextMsg(content);
}
email.send();
email.getMailSession();
} catch (EmailException e) {
logger.error(e.getLocalizedMessage(), e);
return false;
}
return true;
}