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


Java HtmlEmail.setStartTLSEnabled方法代碼示例

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


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

示例1: getHtmlEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
private HtmlEmail getHtmlEmail( String hostName, int port, String username, String password, boolean tls,
    String sender )
    throws EmailException
{
    HtmlEmail email = new HtmlEmail();
    email.setHostName( hostName );
    email.setFrom( sender, customizeTitle( DEFAULT_FROM_NAME ) );
    email.setSmtpPort( port );
    email.setStartTLSEnabled( tls );

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

    return email;
}
 
開發者ID:dhis2,項目名稱:dhis2-core,代碼行數:18,代碼來源:EmailMessageSender.java

示例2: getHtmlEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
private HtmlEmail getHtmlEmail( String hostName, int port, String username, String password, boolean tls, String sender )
    throws EmailException
{
    HtmlEmail email = new HtmlEmail();
    email.setHostName( hostName );
    email.setFrom( defaultIfEmpty( sender, FROM_ADDRESS ), customizeTitle( DEFAULT_FROM_NAME ) );
    email.setSmtpPort( port );
    email.setStartTLSEnabled( tls );

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

    return email;
}
 
開發者ID:ehatle,項目名稱:AgileAlligators,代碼行數:17,代碼來源:EmailMessageSender.java

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

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

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

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