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


Java Email.setStartTLSRequired方法代碼示例

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


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

示例1: createNewEmail

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
private static Email createNewEmail(final NotificationProperties properties) throws EmailException {
    final Email email = new SimpleEmail();
    email.setCharset(Defaults.CHARSET.displayName());
    email.setHostName(properties.getSmtpHostname());
    email.setSmtpPort(properties.getSmtpPort());
    email.setStartTLSRequired(properties.isStartTlsRequired());
    email.setSSLOnConnect(properties.isSslOnConnectRequired());
    email.setAuthentication(properties.getSmtpUsername(), properties.getSmtpPassword());
    final String localhostAddress = LocalhostAddress.INSTANCE.get().orElse("unknown host");
    email.setFrom(properties.getSender(), "RoboZonky @ " + localhostAddress);
    email.addTo(properties.getRecipient());
    return email;
}
 
開發者ID:RoboZonky,項目名稱:robozonky,代碼行數:14,代碼來源:AbstractEmailingListener.java

示例2: initializeEmail

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
private void initializeEmail(final Email email) throws EmailException {
	email.setSocketConnectionTimeout(configuration.getInt("email.connection.timeout", Defaults.SOCKET_CONNECTION_TIMEOUT));
	email.setSocketTimeout(configuration.getInt("email.socket.timeout", Defaults.SOCKET_TIMEOUT));
	email.setStartTLSEnabled(configuration.getBoolean("email.starttls.enabled", Defaults.STARTTLS_ENABLED));
	email.setStartTLSRequired(configuration.getBoolean("email.starttls.required", Defaults.STARTTLS_REQUIRED));
	email.setSSLCheckServerIdentity(configuration.getBoolean("email.ssl.identity", Defaults.SSL_IDENTITY));
	email.setSSLOnConnect(configuration.getBoolean("email.ssl.connect", Defaults.SSL_CONNECT));
	email.setSmtpPort(configuration.getInt("email.port", Defaults.PORT));
	email.setSslSmtpPort(Integer.toString(configuration.getInt("email.ssl.port", Defaults.SSL_PORT)));

	email.setHostName(configuration.getString(CFG_KEY_EMAIL_HOST));

	// Authentication
	if (!configuration.getString(CFG_KEY_EMAIL_USERNAME, true).isEmpty() && !configuration.getString(CFG_KEY_EMAIL_PASSWORD, true).isEmpty()) {
		email.setAuthenticator(new DefaultAuthenticator(configuration.getString(CFG_KEY_EMAIL_USERNAME), configuration.getString(CFG_KEY_EMAIL_PASSWORD)));
	}

	// Sender
	if (configuration.getString(CFG_KEY_EMAIL_FROM_NAME, true).isEmpty()) {
		email.setFrom(configuration.getString(CFG_KEY_EMAIL_FROM_ADDRESS));
	}
	else {
		email.setFrom(configuration.getString(CFG_KEY_EMAIL_FROM_ADDRESS), configuration.getString(CFG_KEY_EMAIL_FROM_NAME));
	}

	// Recipients
	if (!configuration.getString(CFG_KEY_EMAIL_TO_ADDRESSES, true).isEmpty()) {
		email.addTo(configuration.getString(CFG_KEY_EMAIL_TO_ADDRESSES).split(EMAIL_ADDRESSES_SPLIT_REGEX));
	}
	if (!configuration.getString(CFG_KEY_EMAIL_CC_ADDRESSES, true).isEmpty()) {
		email.addCc(configuration.getString(CFG_KEY_EMAIL_CC_ADDRESSES).split(EMAIL_ADDRESSES_SPLIT_REGEX));
	}
	if (!configuration.getString(CFG_KEY_EMAIL_BCC_ADDRESSES, true).isEmpty()) {
		email.addBcc(configuration.getString(CFG_KEY_EMAIL_BCC_ADDRESSES).split(EMAIL_ADDRESSES_SPLIT_REGEX));
	}
}
 
開發者ID:Albertus82,項目名稱:RouterLogger,代碼行數:37,代碼來源:EmailSender.java

示例3: setSecurityMode

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
private Email setSecurityMode(Email email) {
	Integer smtpSecurity = smtpMailSettings.getSecurity();
	String oldTrustStore=(String)System.clearProperty("javax.net.ssl.trustStore");
	LOGGER.debug("oldTrustStore="+oldTrustStore);
	switch (smtpSecurity) {
		case TSiteBean.SECURITY_CONNECTIONS_MODES.NEVER:
			LOGGER.debug("SMTP security connection mode is NEVER");
			break;
		case TSiteBean.SECURITY_CONNECTIONS_MODES.TLS_IF_AVAILABLE:
			LOGGER.debug("SMTP security connection mode is TLS_IF_AVAILABLE");
			email.setStartTLSEnabled(true);
			MailBL.setTrustKeyStore(smtpMailSettings.getHost());
			break;
		case TSiteBean.SECURITY_CONNECTIONS_MODES.TLS:
			LOGGER.debug("SMTP security connection mode is TLS");
			email.setStartTLSEnabled(true);
			email.setStartTLSRequired(true);
			MailBL.setTrustKeyStore(smtpMailSettings.getHost());
			break;
		case TSiteBean.SECURITY_CONNECTIONS_MODES.SSL:{
			LOGGER.debug("SMTP security connection mode is SSL");
			MailBL.setTrustKeyStore(smtpMailSettings.getHost());
			email.setSSLOnConnect(true);
			break;
		}
		default:
			break;
	}
	return email;
}
 
開發者ID:trackplus,項目名稱:Genji,代碼行數:31,代碼來源:MailSender.java

示例4: setupSMTP

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
private static void setupSMTP(Email email, SmtpConfiguration smtpConfig) {
    email.setHostName(smtpConfig.getAddress());
    email.setSmtpPort(smtpConfig.getPort());
    email.setSslSmtpPort(Integer.toString(smtpConfig.getPort()));
    email.setAuthenticator(new DefaultAuthenticator(smtpConfig.getUsername(), smtpConfig.getPassword()));
    email.setStartTLSRequired(smtpConfig.useSSL());
}
 
開發者ID:SEEG-Oxford,項目名稱:ABRAID-MP,代碼行數:8,代碼來源:EmailServiceImpl.java

示例5: apply

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
/**
 * Apply server configuration to email.
 */
@VisibleForTesting
Email apply(final EmailConfiguration configuration, final Email mail) throws EmailException {
  mail.setHostName(configuration.getHost());
  mail.setSmtpPort(configuration.getPort());
  if (!Strings.isNullOrEmpty(configuration.getUsername()) || !Strings.isNullOrEmpty(configuration.getPassword())) {
    mail.setAuthentication(configuration.getUsername(), configuration.getPassword());
  }

  mail.setStartTLSEnabled(configuration.isStartTlsEnabled());
  mail.setStartTLSRequired(configuration.isStartTlsRequired());
  mail.setSSLOnConnect(configuration.isSslOnConnectEnabled());
  mail.setSSLCheckServerIdentity(configuration.isSslCheckServerIdentityEnabled());
  mail.setSslSmtpPort(Integer.toString(configuration.getPort()));

  // default from address
  if (mail.getFromAddress() == null) {
    mail.setFrom(configuration.getFromAddress());
  }

  // apply subject prefix if configured
  String subjectPrefix = configuration.getSubjectPrefix();
  if (subjectPrefix != null) {
    String subject = mail.getSubject();
    mail.setSubject(String.format("%s %s", subjectPrefix, subject));
  }

  // do this last (mail properties are set up from the email fields when you get the mail session)
  if (configuration.isNexusTrustStoreEnabled()) {
    SSLContext context = trustStore.getSSLContext();
    Session session = mail.getMailSession();
    Properties properties = session.getProperties();
    properties.remove(EmailConstants.MAIL_SMTP_SOCKET_FACTORY_CLASS);
    properties.put(EmailConstants.MAIL_SMTP_SSL_ENABLE, true);
    properties.put("mail.smtp.ssl.socketFactory", context.getSocketFactory());
  }

  return mail;
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:42,代碼來源:EmailManagerImpl.java


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