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