當前位置: 首頁>>代碼示例>>Java>>正文


Java Email.setCharset方法代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:progolden,項目名稱:vraptor-boilerplate,代碼行數:19,代碼來源:EmailUtils.java

示例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);
        }
    }
}
 
開發者ID:imCodePartnerAB,項目名稱:imcms,代碼行數:20,代碼來源:SMTP.java

示例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();
}
 
開發者ID:touyouHacker,項目名稱:SutemaBurstStream,代碼行數:20,代碼來源:SutemaBurstStreamMain.java

示例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);

	}
}
 
開發者ID:ivarptr,項目名稱:clobaframe,代碼行數:26,代碼來源:SmtpMailSender.java

示例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;
}
 
開發者ID:RoboZonky,項目名稱:robozonky,代碼行數:14,代碼來源:AbstractEmailingListener.java

示例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());
}
 
開發者ID:yinshipeng,項目名稱:sosoapi-base,代碼行數:16,代碼來源:ApacheMailServiceImpl.java

示例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);
    }        
}
 
開發者ID:svenkubiak,項目名稱:mangooio,代碼行數:31,代碼來源:Mail.java

示例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);
		}
	}

}
 
開發者ID:caelum,項目名稱:mamute,代碼行數:36,代碼來源:NewsletterMailer.java

示例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);
	}
}
 
開發者ID:caelum,項目名稱:mamute,代碼行數:11,代碼來源:NotificationMailer.java

示例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;
}
 
開發者ID:KylinOLAP,項目名稱:Kylin,代碼行數:42,代碼來源:MailService.java

示例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!");

}
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:64,代碼來源:SendEmaiWithGmail.java

示例12: setCharset

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
protected void setCharset(Email email, String charSetStr) {
    if (charset != null) {
        email.setCharset(charSetStr);
    }
}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:6,代碼來源:MailActivityBehavior.java

示例13: setCharset

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
protected void setCharset(Email email, String charSetStr) {
  if (charset != null) {
    email.setCharset(charSetStr);
  }
}
 
開發者ID:logicalhacking,項目名稱:SecureBPMN,代碼行數:6,代碼來源:MailActivityBehavior.java

示例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;
}
 
開發者ID:apache,項目名稱:kylin,代碼行數:53,代碼來源:MailService.java


注:本文中的org.apache.commons.mail.Email.setCharset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。