本文整理匯總了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;
}