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


Java HtmlEmail.attach方法代碼示例

本文整理匯總了Java中org.apache.commons.mail.HtmlEmail.attach方法的典型用法代碼示例。如果您正苦於以下問題:Java HtmlEmail.attach方法的具體用法?Java HtmlEmail.attach怎麽用?Java HtmlEmail.attach使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.mail.HtmlEmail的用法示例。


在下文中一共展示了HtmlEmail.attach方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doSend

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
private void doSend(String recipient, String sender, Set<String> cc, String subject, String content,
                    EmailAttachment... attachments) throws EmailException {
    HtmlEmail email = new HtmlEmail();
    email.setCharset("utf-8");
    for (EmailAttachment attachment : attachments) {
        email.attach(attachment);
    }
    email.setHostName(HOST);
    email.setSmtpPort(PORT);
    email.setAuthenticator(new DefaultAuthenticator(USER, PWD));
    email.setSSLOnConnect(USE_SSL);
    email.setSubject(subject);
    email.addTo(recipient);
    email.setFrom(String.format("Exam <%s>", SYSTEM_ACCOUNT));
    email.addReplyTo(sender);
    for (String addr : cc) {
        email.addCc(addr);
    }
    email.setHtmlMsg(content);
    if (USE_MOCK) {
        mockSending(email, content, attachments);
    } else {
        email.send();
    }
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:26,代碼來源:EmailSenderImpl.java

示例2: sendHtmlEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
private void sendHtmlEmail() throws MangooMailerException {
    Config config = Application.getInstance(Config.class);
    try {
        HtmlEmail htmlEmail = new HtmlEmail();
        htmlEmail.setCharset(Default.ENCODING.toString());
        htmlEmail.setHostName(config.getSmtpHost());
        htmlEmail.setSmtpPort(config.getSmtpPort());
        htmlEmail.setAuthenticator(getDefaultAuthenticator());
        htmlEmail.setSSLOnConnect(config.isSmtpSSL());
        htmlEmail.setFrom(this.from);
        htmlEmail.setSubject(this.subject);
        htmlEmail.setHtmlMsg(render());
        
        for (String recipient : this.recipients) {
            htmlEmail.addTo(recipient);
        }
        
        for (String cc : this.ccRecipients) {
            htmlEmail.addCc(cc);
        }
        
        for (String bcc : this.bccRecipients) {
            htmlEmail.addBcc(bcc);
        }
        
        for (File file : this.files) {
            htmlEmail.attach(file);
        }
        
        htmlEmail.send();
    } catch (EmailException | MangooTemplateEngineException e) {
        throw new MangooMailerException(e);
    } 
}
 
開發者ID:svenkubiak,項目名稱:mangooio,代碼行數:35,代碼來源:Mail.java

示例3: sendEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
/**
 * Simple method to send a single email using the EMailServerSettings.
 *
 * @param settings
 * @param fromAddress
 * @param firstAddress
 * @param object2
 * @param object
 * @param subject
 * @param body
 * @param attachedFiles
 * @param string
 * @throws EmailException
 */
public void sendEmail(final SMTPServerSetting settings, final String fromAddress, String bounceEmailAddress,
		final List<EmailTarget> targets, final String subject, final String body,
		final HashSet<? extends DataSource> attachedFiles) throws EmailException
{
	final HtmlEmail email = new HtmlEmail();

	email.setDebug(true);
	email.setHostName(settings.getSmtpFQDN());
	email.setSmtpPort(settings.getSmtpPort());
	email.setSSLCheckServerIdentity(false);
	if (settings.isAuthRequired())
	{
		email.setAuthentication(settings.getUsername(), settings.getPassword());
	}
	if (settings.getUseSSL())
	{
		email.setSslSmtpPort(settings.getSmtpPort().toString());
		email.setSSLOnConnect(true);
		email.setSSLCheckServerIdentity(false);
	}
	email.setFrom(fromAddress);
	email.setBounceAddress(bounceEmailAddress);

	for (final EmailTarget target : targets)
	{
		addEmailAddress(email, target.emailAddress, target.type);
	}

	email.setSubject(subject);
	email.setHtmlMsg(body);
	email.setTextMsg("Your email client does not support HTML messages");
	if (attachedFiles != null)
	{
		for (final DataSource attachedFile : attachedFiles)
		{
			email.attach(attachedFile, attachedFile.getName(), attachedFile.getContentType());
		}
	}

	email.send();

}
 
開發者ID:bsutton,項目名稱:scoutmaster,代碼行數:57,代碼來源:SMTPSettingsDao.java


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