本文整理汇总了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;
}
示例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));
}
}
示例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;
}
示例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());
}
示例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;
}