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


Java HtmlEmail.addTo方法代碼示例

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


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

示例1: sendEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
private void sendEmail(String content) throws Exception {
	System.out.println("Send Email:");
	if (!Config.getBoolean("email.enabled")) {
		return;
	}
	
	HtmlEmail email = new HtmlEmail();
	for (String receipt : Config.getArrayProperty("report.email.recipients")) {
		email.addTo(receipt);
	}
	email.setFrom(Config.getProperty("report.email.from"));
	email.setSubject(Config.getProperty("report.email.subject"));
	email.setHtmlMsg(content);
	email.setHostName(Config.getProperty("report.email.host"));
	email.setAuthentication(Config.getProperty("report.email.username"), 
			Config.getProperty("report.email.password"));
	email.send();
}
 
開發者ID:21ca,項目名稱:selenium-testng-template,代碼行數:19,代碼來源:SendEmailReporter.java

示例2: 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

示例3: main

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
/**
 * This main method is useful when debugging smtp configuration problems.
 */
public static void main(String... argv) throws EmailException
{
		// gmail : smtp.gmail.com:465		
	
		String fromEmailAddress=argv[0];
		String toEmailAddress=argv[1];
		String smtpServer=argv[2];
		
		String smtpPort=(argv.length>3?argv[3]:null);
		String smtpUser=(argv.length>4?argv[4]:null);
		String smtpPassword=(argv.length>5?argv[4]:null);
                       String connectionSecurity=(argv.length>6?argv[5]:null);
		HtmlEmail htmlEmail=EmailUtilsOld.getHtmlEmail(smtpServer, smtpPort, smtpUser, smtpPassword, connectionSecurity);

		htmlEmail.addTo(toEmailAddress, toEmailAddress);
		htmlEmail.setFrom(fromEmailAddress, fromEmailAddress);

		htmlEmail.setSubject("test subject");
		htmlEmail.setTextMsg("test contents "+(new java.util.Date()));

		htmlEmail.send();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:26,代碼來源:EmailUtilsOld.java

示例4: sendEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
private void sendEmail() throws EmailException
{
	HtmlEmail email = new HtmlEmail();
	email.setHostName(smtpServer);
	if (smtpUser != null && smtpPassword != null) email.setAuthentication(smtpUser, smtpPassword);

	if (smtpSslPort != null)
	{
		email.setSSL(true);
		email.setSslSmtpPort(smtpSslPort);
	}

	Session session = email.getMailSession();
	Properties properties = session.getProperties();
	properties.setProperty("mail.smtp.connectiontimeout", "20000");
	properties.setProperty("mail.smtp.timeout", "20000");

	email.addTo(recipientEmailAddress, recipientEmailAddress);
	email.setFrom(smtpUser, smtpUser);

	email.setSubject(subject);
	email.setHtmlMsg(contents);
	email.setTextMsg(contents);
	email.send();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:26,代碼來源:Log4JGmailExecutorTask.java

示例5: send

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
public static void send(Mail mail) {
    HtmlEmail email = new HtmlEmail();
    try {
        email.setHostName(mail.getHost());
        email.setCharset(Config.UTF_8);
        email.addTo(mail.getReceiver());
        email.setFrom(mail.getSender(), mail.getName());
        email.setAuthentication(mail.getUsername(), mail.getPassword());
        email.setSubject(mail.getSubject());
        email.setMsg(mail.getMessage());
        email.setSmtpPort(mail.getSmtpPort());
        email.send();
    } catch (EmailException e) {
        e.printStackTrace();
    }
}
 
開發者ID:fku233,項目名稱:MBLive,代碼行數:17,代碼來源:MailKit.java

示例6: sendCommonMail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
/**
 * 發送普通郵件
 * 
 * @param toMailAddr
 *            收信人地址
 * @param subject
 *            email主題
 * @param message
 *            發送email信息
 */
public static void sendCommonMail(String toMailAddr, String subject,
		String message) {
	HtmlEmail hemail = new HtmlEmail();
	try {
		hemail.setHostName(getHost(from));
		hemail.setSmtpPort(getSmtpPort(from));
		hemail.setCharset(charSet);
		hemail.addTo(toMailAddr);
		hemail.setFrom(from, fromName);
		hemail.setAuthentication(username, password);
		hemail.setSubject(subject);
		hemail.setMsg(message);
		hemail.send();
		System.out.println("email send true!");
	} catch (Exception e) {
		e.printStackTrace();
		System.out.println("email send error!");
	}

}
 
開發者ID:EleTeam,項目名稱:Shop-for-JavaWeb,代碼行數:31,代碼來源:SendMailUtil.java

示例7: sendMailByApache

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
public static void sendMailByApache(String to, String title, String content) {

        try {
            HtmlEmail email = new HtmlEmail();
            // 這裏是發送服務器的名字
            email.setHostName(smtpHost);
            // 編碼集的設置
            email.setTLS(true);
            email.setSSL(true);

            email.setCharset("utf-8");
            // 收件人的郵箱
            email.addTo(to);
            // 發送人的郵箱
            email.setFrom(fromEmail);
            // 如果需要認證信息的話,設置認證:用戶名-密碼。分別為發件人在郵件服務器上的注冊名稱和密碼
            email.setAuthentication(username, password);
            email.setSubject(title);
            // 要發送的信息
            email.setMsg(content);
            // 發送
            email.send();
        } catch (EmailException e) {
            Log.i("EmailUtil", e.getMessage());
        }
    }
 
開發者ID:PureDark,項目名稱:H-Viewer,代碼行數:27,代碼來源:EmailUtil.java

示例8: test

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
/**
 * send mail
 */
@Test
public void test() {
    try {
        HtmlEmail htmlEmail = new HtmlEmail();
        htmlEmail.setHostName("smtp.qq.com");
        htmlEmail.setFrom("[email protected]", "[email protected]");
        htmlEmail.addTo("[email protected]");
        htmlEmail.addCc("[email protected]", "[email protected]");
        htmlEmail.setAuthentication("[email protected]", "TaylorSwift");
        htmlEmail.setSubject("email example");
        htmlEmail.setHtmlMsg("test apache email");
        htmlEmail.setCharset("UTF-8");
        htmlEmail.buildMimeMessage();
        htmlEmail.sendMimeMessage();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }
}
 
開發者ID:sunlin901203,項目名稱:example-java,代碼行數:22,代碼來源:EmailExample.java

示例9: sendHtmlAndTextEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
@Override
public void sendHtmlAndTextEmail(String to, String subject, String htmlBody, String textBody) throws ServiceException {
	HtmlEmail email = new HtmlEmail();

	try {
		setupEmail(email);
		validateAddress(to);
		email.addTo(to);
		email.setSubject(subject);
		email.setHtmlMsg(htmlBody);
		email.setTextMsg(textBody);
		email.send();
	} catch (EmailException e) {
		log.error("ZZZ.EmailException. To: " + to + " Subject: " + subject, e);
		throw new ServiceException("Unable to send email.", e);
	}
}
 
開發者ID:SmarterApp,項目名稱:TechnologyReadinessTool,代碼行數:18,代碼來源:EmailServiceImpl.java

示例10: sendHtmlEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
@Override
public void sendHtmlEmail(String to, String subject, String htmlBody) throws ServiceException {
	HtmlEmail email = new HtmlEmail();

	try {
		setupEmail(email);
		validateAddress(to);
		email.addTo(to);
		email.setSubject(subject);
		email.setHtmlMsg(htmlBody);
		email.send();
	} catch (EmailException e) {
		log.error("ZZZ.EmailException. To: " + to + " Subject: " + subject, e);
		throw new ServiceException("Unable to send email.", e);
	}
}
 
開發者ID:SmarterApp,項目名稱:TechnologyReadinessTool,代碼行數:17,代碼來源:EmailServiceImpl.java

示例11: sendEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
public void sendEmail() {
	HtmlEmail email = new HtmlEmail();
	try {
		email.setHostName(emailHostName);
		email.setSmtpPort(smtpPort);
		email.setAuthenticator(new DefaultAuthenticator(emailLogin,
				emailPassword));
		email.setSSLOnConnect(emailSSL);
		email.setStartTLSEnabled(startTLS);
		email.setFrom(emailSender);
		email.setSubject(title);
		email.setHtmlMsg(htmlMessage);
		email.addTo(emailRecipient);
		email.send();
		System.out.println("Email sent: " + title);
	} catch (EmailException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:RobCubed,項目名稱:ShipworksWeeklyReports,代碼行數:21,代碼來源:Email.java

示例12: sendEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
/** Sends email according to the provided config. */
private static void sendEmail(SmtpConfiguration config, HtmlEmail email, String subject,
    String fromAddress, String toAddress) throws EmailException {
  if (config != null) {
    email.setSubject(subject);
    LOG.info("Sending email to {}", toAddress);
    email.setHostName(config.getSmtpHost());
    email.setSmtpPort(config.getSmtpPort());
    if (config.getSmtpUser() != null && config.getSmtpPassword() != null) {
      email.setAuthenticator(
          new DefaultAuthenticator(config.getSmtpUser(), config.getSmtpPassword()));
      email.setSSLOnConnect(true);
    }
    email.setFrom(fromAddress);
    for (String address : toAddress.split(EMAIL_ADDRESS_SEPARATOR)) {
      email.addTo(address);
    }
    email.send();
    LOG.info("Email sent with subject [{}] to address [{}]!", subject, toAddress);
  } else {
    LOG.error("No email config provided for email with subject [{}]!", subject);
  }
}
 
開發者ID:linkedin,項目名稱:pinot,代碼行數:24,代碼來源:EmailHelper.java

示例13: sendWithHtml

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
@Override
public void sendWithHtml(String recipient, String subject, String content) throws SendMailException {
	Assert.hasText(recipient);
	Assert.hasText(subject);
	Assert.hasText(content);
	
	HtmlEmail email = new HtmlEmail();
	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.setHtmlMsg(content);
		//email.setMsg(""); // can set plain text either
		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

示例14: main

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
/**
 * This main method is useful when debugging smtp configuration problems.
 */
public static void main(String... argv) throws EmailException
{
		// gmail : smtp.gmail.com:465		
	
		String fromEmailAddress=argv[0];
		String toEmailAddress=argv[1];
		String smtpServer=argv[2];
		
		String smtpPort=(argv.length>3?argv[3]:null);
		String smtpUser=(argv.length>4?argv[4]:null);
		String smtpPassword=(argv.length>5?argv[4]:null);
                       String connectionSecurity=(argv.length>6?argv[5]:null);
		HtmlEmail htmlEmail=EmailUtils.getHtmlEmail(smtpServer, smtpPort, smtpUser, smtpPassword, connectionSecurity);

		htmlEmail.addTo(toEmailAddress, toEmailAddress);
		htmlEmail.setFrom(fromEmailAddress, fromEmailAddress);

		htmlEmail.setSubject("test subject");
		htmlEmail.setTextMsg("test contents "+(new java.util.Date()));

		htmlEmail.send();
}
 
開發者ID:oscarservice,項目名稱:oscar-old,代碼行數:26,代碼來源:EmailUtils.java

示例15: send

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
/**
 * Send email with subject and message body.
 * @param subject the email subject.
 * @param body the email body.
 */
public void send(String subject, String body) {
    try {
        HtmlEmail email = new HtmlEmail();
        email.setHostName(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_HOST, "localhost"));
        email.setSmtpPort(configuration.getInt(CONFKEY_REPORTS_MAILER_SMTP_PORT, 465));
        email.setAuthenticator(new DefaultAuthenticator(
            configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_USER, "anonymous"),
            configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_PASS, "guest")
        ));
        email.setStartTLSEnabled(false);
        email.setSSLOnConnect(configuration.getBoolean(CONFKEY_REPORTS_MAILER_SMTP_SSL, true));
        email.setFrom(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_FROM, ""));
        email.setSubject(subject);
        email.setHtmlMsg(body);
        String[] receivers = configuration.getStringArray(CONFKEY_REPORTS_MAILER_SMTP_TO);
        for (String receiver : receivers) {
            email.addTo(receiver);
        }
        email.send();
        LOG.info("Report sent with email to " + email.getToAddresses().toString() + " (\"" + subject + "\")");
    } catch (EmailException e) {
        LOG.error(e.getMessage(), e);
    }
}
 
開發者ID:dma-ais,項目名稱:AisAbnormal,代碼行數:30,代碼來源:ReportMailer.java


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