当前位置: 首页>>代码示例>>Java>>正文


Java HtmlEmail.setSSLOnConnect方法代码示例

本文整理汇总了Java中org.apache.commons.mail.HtmlEmail.setSSLOnConnect方法的典型用法代码示例。如果您正苦于以下问题:Java HtmlEmail.setSSLOnConnect方法的具体用法?Java HtmlEmail.setSSLOnConnect怎么用?Java HtmlEmail.setSSLOnConnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.mail.HtmlEmail的用法示例。


在下文中一共展示了HtmlEmail.setSSLOnConnect方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

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

示例5: sendHtml

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
@Override
public boolean sendHtml(String to, String subject, String content) throws EmailException {
	HtmlEmail email = new HtmlEmail();
	email.setHostName(host);// 设置使用发电子邮件的邮件服务器
	email.addTo(to);
	email.setAuthentication(user, password);
	email.setFrom(user);
	email.setSubject(subject);
	email.setMsg(content);
	email.setSSLOnConnect(true);
	email.setSslSmtpPort("465"); // 若启用,设置smtp协议的SSL端口号
	email.send();
	return true;
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:15,代码来源:MailClientImpl.java

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

示例7: getHtmlEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public HtmlEmail getHtmlEmail() {
    HtmlEmail email = new HtmlEmail();

    email.setHostName(hostname);
    email.setSmtpPort(port);

    if (username != null && password != null && !username.isEmpty()) {
        email.setAuthenticator(new DefaultAuthenticator(username, password));
    }

    email.setSSLOnConnect(sslOnConnect);
    email.setStartTLSEnabled(startTslEnabled);
    email.setStartTLSRequired(requireTsl);

    return email;
}
 
开发者ID:UKHomeOffice,项目名称:email-api,代码行数:17,代码来源:HtmlEmailFactoryImpl.java

示例8: sendSupportEmail

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public boolean sendSupportEmail() {
    try {
        String senderName = sender_name.getText();
        String senderEmail = sender_email.getText();
        String sendingTime = date_time.getText();
        String systemUser = system_user.getText();

        String message = messge_content.getText();

        if (message.isEmpty()) {
            JOptionPane.showMessageDialog(this, "You haven't entered your message. Please enter the message and try again.");
        }

        // Create the email message
        HtmlEmail email = new HtmlEmail();
        email.setHostName("host url");
        email.addTo("sender email", "Sender Name");
        email.setFrom("from email", "From Name");
        email.setAuthentication("username", "password");
        email.setSSLOnConnect(true);
        email.setStartTLSEnabled(true);
        email.addReplyTo("[email protected]", "Support Service - Company");
        email.setSmtpPort(465);

        email.setSubject("New Support Request from Application");

        // embed the image and get the content id
        URL url = getClass().getResource("/app/resources/shield_icon16x16.png");
        String cid = email.embed(url, "Application Logo");

        URL template = getClass().getResource("/app/support/email_template_20161101_isuru.emailtemplate");

        byte[] encoded = Files.readAllBytes(Paths.get(template.toURI()));
        String htmlMessage = new String(encoded, StandardCharsets.UTF_8);

        htmlMessage = htmlMessage.replace("_EP1_", "cid:" + cid);
        htmlMessage = htmlMessage.replace("_EP2_", systemUser);
        htmlMessage = htmlMessage.replace("_EP3_", senderName + "(" + senderEmail + ")");
        htmlMessage = htmlMessage.replace("_EP4_", sendingTime);
        htmlMessage = htmlMessage.replace("_EP5_", message.replaceAll("\\r?\\n", "<br />"));

        // set the html message
        email.setHtmlMsg(htmlMessage);

        String textMessage = "Application - Support Request\n"
                + "---------------------------------------------------------------------\n"
                + "New Support Request from P1\n"
                + "Sent by P2 on P3\n"
                + "---------------------------------------------------------------------\n"
                + "\n"
                + "Message: \nP4\n"
                + "\n"
                + "---------------------------------------------------------------------\n"
                + "This is an automatically generated email sent from Application.\n"
                + "\n"
                + "© All Rights Reserved - Management Development Co-operative Co. Ltd.";

        textMessage = textMessage.replace("P1", systemUser);
        textMessage = textMessage.replace("P2", senderName + "(" + senderEmail + ")");
        textMessage = textMessage.replace("P3", sendingTime);
        textMessage = textMessage.replace("P4", message);

        // set the alternative message
        email.setTextMsg(textMessage);

        // send the email
        email.send();
        return true;
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "Cannot send email.\nError:" + e.getLocalizedMessage(), "Sending failure", JOptionPane.ERROR_MESSAGE);
        return false;
    }
}
 
开发者ID:isu3ru,项目名称:java-swing-template,代码行数:74,代码来源:Support.java

示例9: main

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    Email email = new SimpleEmail();
    email.setHostName("smtp.googlemail.com");
    email.setSSLOnConnect(false); //OK

    Email email2 = new SimpleEmail();
    email2.setHostName("smtp2.googlemail.com");        
    email2.setSSLOnConnect(true); //BAD
    //email2.setSmtpPort(465);
    //email2.setAuthenticator(new DefaultAuthenticator("username", "password"));
    //email2.setFrom("[email protected]");
    //email2.setSubject("TestMail");
    //email2.setMsg("This is a test mail ... :-)");
    //email2.addTo("[email protected]");
    //email2.send();

    MultiPartEmail emailMulti = new MultiPartEmail();
    emailMulti.setHostName("mail.myserver.com");
    emailMulti.setSSLOnConnect(true); //BAD

    HtmlEmail htmlEmail = new HtmlEmail();
    htmlEmail.setHostName("mail.myserver.com");
    htmlEmail.setSSLOnConnect(true); //BAD

    ImageHtmlEmail imageEmail = new ImageHtmlEmail();
    imageEmail.setHostName("mail.myserver.com");
    imageEmail.setSSLOnConnect(true);
    imageEmail.setSSLCheckServerIdentity(true); //OK
    
    ImageHtmlEmail imageEmail2 = new ImageHtmlEmail();
    imageEmail2.setHostName("mail2.myserver.com");
    imageEmail2.setSSLCheckServerIdentity(true); //OK - reversed order
    imageEmail2.setSSLOnConnect(true);

    ImageHtmlEmail imageEmail3 = new ImageHtmlEmail();
    imageEmail3.setHostName("mail3.myserver.com");
    imageEmail3.setSSLOnConnect(true); //BAD
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:39,代码来源:InsecureSmtpSsl.java

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

示例11: setPropertiesForPort

import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
 * Sets properties to the given HtmlEmail object based on the port from which it will be sent.
 *
 * @param email the email object to configure
 * @param port the configured outgoing port
 */
private void setPropertiesForPort(HtmlEmail email, int port) throws EmailException {
    switch (port) {
        case 587:
            String oAuth2Token = settings.getProperty(EmailSettings.OAUTH2_TOKEN);
            if (!oAuth2Token.isEmpty()) {
                if (Security.getProvider("Google OAuth2 Provider") == null) {
                    Security.addProvider(new OAuth2Provider());
                }
                Properties mailProperties = email.getMailSession().getProperties();
                mailProperties.setProperty("mail.smtp.ssl.enable", "true");
                mailProperties.setProperty("mail.smtp.auth.mechanisms", "XOAUTH2");
                mailProperties.setProperty("mail.smtp.sasl.enable", "true");
                mailProperties.setProperty("mail.smtp.sasl.mechanisms", "XOAUTH2");
                mailProperties.setProperty("mail.smtp.auth.login.disable", "true");
                mailProperties.setProperty("mail.smtp.auth.plain.disable", "true");
                mailProperties.setProperty(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oAuth2Token);
                email.setMailSession(Session.getInstance(mailProperties));
            } else {
                email.setStartTLSEnabled(true);
                email.setStartTLSRequired(true);
            }
            break;
        case 25:
            if (settings.getProperty(EmailSettings.PORT25_USE_TLS)) {
                email.setStartTLSEnabled(true);
                email.setSSLCheckServerIdentity(true);
            }
            break;
        case 465:
            email.setSslSmtpPort(Integer.toString(port));
            email.setSSLOnConnect(true);
            break;
        default:
            email.setStartTLSEnabled(true);
            email.setSSLOnConnect(true);
            email.setSSLCheckServerIdentity(true);
    }
}
 
开发者ID:AuthMe,项目名称:AuthMeReloaded,代码行数:45,代码来源:SendMailSsl.java


注:本文中的org.apache.commons.mail.HtmlEmail.setSSLOnConnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。