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


Java Email.setStartTLSEnabled方法代码示例

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


在下文中一共展示了Email.setStartTLSEnabled方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureConnection

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private static void configureConnection(Email email) {
	try {
		email.setSmtpPort(SMTP_PORT);
		email.setHostName(SMTP_HOST);
		email.setCharset(CHARSET);
		if (!GeneralUtils.isEmpty(SMTP_USER)) {
			email.setAuthentication(
				SMTP_USER,
				SMTP_PASSWORD
			);
		}
		email.setSSLOnConnect(SMTP_SSL);
		email.setStartTLSEnabled(SMTP_TLS);
	} catch (Throwable ex) {
		LOG.error("Erro ao configurar o email.", ex);
		throw new RuntimeException("Error configuring smtp connection.", ex);
	}
}
 
开发者ID:progolden,项目名称:vraptor-boilerplate,代码行数:19,代码来源:EmailUtils.java

示例2: applySendSettings

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
/**
 * Applies {@link SmtpClientConfig} options to the {@link Email} being sent.
 *
 * @param email
 *            Email to be sent.
 * @param settings
 *            Send settings to apply to the email
 */
private void applySendSettings(Email email, SmtpClientConfig settings) {
    email.setHostName(settings.getSmtpHost());
    email.setSmtpPort(settings.getSmtpPort());
    email.setSslSmtpPort(String.valueOf(settings.getSmtpPort()));
    if (settings.getAuthentication() != null) {
        email.setAuthentication(settings.getAuthentication().getUsername(),
                settings.getAuthentication().getPassword());
    }
    if (settings.isUseSsl()) {
        // enable the use of SSL for SMTP connections. NOTE: should
        // only be used for cases when the SMTP server port only supports
        // SSL connections (typically over port 465).
        email.setSSLOnConnect(true);
    } else {
        // Support use of the STARTTLS command (see RFC 2487 and RFC 3501)
        // to switch the connection to be secured by TLS for cases where the
        // server supports both SSL and non-SSL connections. This is
        // typically the case for most modern mail servers.
        email.setStartTLSEnabled(true);
    }
    // trust all mail server host certificates
    System.setProperty("mail.smtp.ssl.trust", "*");
    email.setSocketConnectionTimeout(settings.getConnectionTimeout());
    email.setSocketTimeout(settings.getSocketTimeout());
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:34,代码来源:SmtpSender.java

示例3: setEncryption

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private void setEncryption(Email mail) {
    final String encryptionProtocol = getServerProperty("encryption.protocol");
    final String accountMail = getServerProperty("mail.address");
    final String accountMailPassword = getServerProperty("mail.password");

    if ((encryptionProtocol != null) && (accountMail != null) && (accountMailPassword != null)) {
        if (encryptionProtocol.toLowerCase().equals("tls")) {
            mail.setStartTLSEnabled(true);

        } else if (encryptionProtocol.toLowerCase().equals("ssl")) {
            mail.setSSLOnConnect(true);

        } else {
            return;
        }

        mail.setAuthenticator(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(accountMail, accountMailPassword);
            }
        });
    }
}
 
开发者ID:imCodePartnerAB,项目名称:imcms,代码行数:25,代码来源:SMTP.java

示例4: initEmail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private void initEmail(Email email,String fromEmail, String fromPasswd,String fromName,
						String host,List<String> toEmailList,MailMsg mailMsg) throws EmailException{
	email.setHostName(host);
    //邮件服务器验证:用户名/密码
    email.setAuthentication(fromEmail, fromPasswd);
    //必须放在前面,否则乱码
    email.setCharset(MailCfg.CHARSET);
    email.setDebug(false);//是否开启调试默认不开启  
       email.setSSLOnConnect(true);//开启SSL加密  
       email.setStartTLSEnabled(true);//开启TLS加密 
       
       email.addTo(toEmailList.toArray(new String[0]));
   	email.setFrom(fromEmail,fromName);
   	email.setSubject(mailMsg.getSubject());
}
 
开发者ID:yinshipeng,项目名称:sosoapi-base,代码行数:16,代码来源:ApacheMailServiceImpl.java

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

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

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

示例8: sendEmail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
/**
 * Send an email. The email server/authentication details are extracted from the supplied configuration.
 * 
 * <p>
 *   The following configuration values are used:
 * </p>
 * <ul>
 *   <li>
 *     {@code email.starttls} Indicates whether or not STARTTLS should be used ({@code true/false}). If not present, {@code false} is assumed.
 *   </li>
 *   <li>
 *     {@code email.ssl} Indicates whether or not SSL should be used ({@code true/false}). If not present, {@code false} is assumed.
 *   </li>
 *   <li>
 *     {@code email.host} The email server.
 *   </li>
 *   <li>
 *     {@code email.port} The port on the email server.
 *   </li>
 *   <li>
 *     {@code email.username} The username for authentication on the email server. If this is not present (or empty), authentication will not be attempted.
 *   </li>
 *   <li>
 *     {@code email.password} The password for authentication on the email server (if authentication is being used).
 *   </li>
 *   <li>
 *     {@code email.fromaddress} The From address for emails sent by the application.
 *   </li>
 *   <li>
 *     {@code email.fromname} The From name for emails sent by the application. 
 *   </li>
 * </ul>
 * 
 * 
 * @param config The application configuration
 * @param address The destination email address
 * @param subject The email subject
 * @param message The email contents
 * @throws EmailException If the email could not be sent
 */
public static void sendEmail(Properties config, String address, String subject, String message) throws EmailException {
	Email email = new SimpleEmail();

	email.setStartTLSEnabled(Boolean.valueOf(config.getProperty("email.starttls", "false")));
	email.setSSLOnConnect(Boolean.valueOf(config.getProperty("email.ssl", "false")));
	
	email.setHostName(config.getProperty("email.hostname"));
	email.setSmtpPort(Integer.parseInt(config.getProperty("email.port")));
	
	String userName = config.getProperty("email.username");
	if (null != userName && userName.trim().length() > 0) {
		email.setAuthentication(config.getProperty("email.username"), config.getProperty("email.password"));
	}
	email.setFrom(config.getProperty("email.fromaddress"), config.getProperty("email.fromname"));
	email.setSubject(subject);
	email.setMsg(message);
	email.addTo(address);
	email.send();
}
 
开发者ID:BjerknesClimateDataCentre,项目名称:QuinCe,代码行数:60,代码来源:EmailSender.java

示例9: sendMail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
/**
 * @param receivers
 * @param subject
 * @param content
 * @return true or false indicating whether the email was delivered successfully
 * @throws IOException
 */
public boolean sendMail(List<String> receivers, String subject, String content, boolean isHtmlMsg) {

    if (!enabled) {
        logger.info("Email service is disabled; this mail will not be delivered: " + subject);
        logger.info("To enable mail service, set 'kylin.job.notification-enabled=true' in kylin.properties");
        return false;
    }

    Email email = new HtmlEmail();
    email.setHostName(host);
    email.setStartTLSEnabled(starttlsEnabled);
    if (starttlsEnabled) {
        email.setSslSmtpPort(port);
    } else {
        email.setSmtpPort(Integer.valueOf(port));
    }
    
    if (username != null && username.trim().length() > 0) {
        email.setAuthentication(username, password);
    }

    //email.setDebug(true);
    try {
        for (String receiver : receivers) {
            email.addTo(receiver);
        }

        email.setFrom(sender);
        email.setSubject(subject);
        email.setCharset("UTF-8");
        if (isHtmlMsg) {
            ((HtmlEmail) email).setHtmlMsg(content);
        } else {
            ((HtmlEmail) email).setTextMsg(content);
        }
        email.send();
        email.getMailSession();

    } catch (EmailException e) {
        logger.error(e.getLocalizedMessage(), e);
        return false;
    }

    return true;
}
 
开发者ID:apache,项目名称:kylin,代码行数:53,代码来源:MailService.java


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