当前位置: 首页>>代码示例>>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;未经允许,请勿转载。