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


Java Email.setSocketTimeout方法代码示例

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


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

示例1: createEmail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
protected Email createEmail() {
    Email email = new SimpleEmail();
    email.setHostName(config.readString(ConfigProperty.SMTP_HOST_NAME));
    email.setSSLOnConnect(config.readBoolean(ConfigProperty.SMTP_USE_SSL));
    if (config.readBoolean(ConfigProperty.SMTP_USE_SSL)) {
        email.setSslSmtpPort(config.readString(ConfigProperty.SMTP_PORT));
    } else {
        email.setSmtpPort(config.readInt(ConfigProperty.SMTP_PORT));
    }
    if (config.readBoolean(ConfigProperty.SMTP_AUTH)) {
        email.setAuthenticator(new DefaultAuthenticator(config.readString(ConfigProperty.SMTP_DEFAULT_USERNAME),
                config.readString(ConfigProperty.SMTP_DEFAULT_PASSWORD)));
    }
    try {
        email.setFrom(config.readString(ConfigProperty.EMAIL_DEFAULT_FROM),
                config.readString(ConfigProperty.EMAIL_DEFAULT_FROM_NAME));
    } catch (EmailException e) {
        throw Exceptions.runtime(e);
    }
    email.setSocketConnectionTimeout(config.readInt(ConfigProperty.SMTP_CONNECTION_TIMEOUT));
    email.setSocketTimeout(config.readInt(ConfigProperty.SMTP_SEND_TIMEOUT));
    return email;
}
 
开发者ID:dmart28,项目名称:gcplot,代码行数:24,代码来源:SMTPMailProvider.java

示例2: sendEmail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private void sendEmail() throws EmailException, UnknownHostException {

		List<String> addresses =
				Lists.newArrayList(Splitter.on(',')
						.omitEmptyStrings()
						.trimResults()
						.split(ADMIN_EMAIL.getAdmins()));
		logger.info("Sending email to {}", addresses.toString());


		Email email = new HtmlEmail();
		email.setHostName(ADMIN_EMAIL.getHost());
		email.setSocketTimeout(30000); // 30 seconds
		email.setSocketConnectionTimeout(30000); // 30 seconds
		for (String address : addresses) {
			email.addTo(address);
		}
		email.setFrom(SorcererInjector.get().getModule().getName() + "@" +
				InetAddress.getLocalHost().getHostName());
		email.setSubject(title);
		email.setMsg(body);
		email.send();

	}
 
开发者ID:turn,项目名称:sorcerer,代码行数:25,代码来源:Emailer.java

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

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

示例5: getEmail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private Email getEmail(final MailTemplate mailTemplate,
                       final Class<? extends Email> mailType,
                       final Map<String, String> params) throws EmailException, MessagingException, IOException {

    final Email email = mailTemplate.getEmail(StrLookup.mapLookup(params), mailType);

    if (params.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS)
            && params.containsKey(EmailServiceConstants.SENDER_NAME)) {

        email.setFrom(
                params.get(EmailServiceConstants.SENDER_EMAIL_ADDRESS),
                params.get(EmailServiceConstants.SENDER_NAME));

    } else if (params.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS)) {
        email.setFrom(params.get(EmailServiceConstants.SENDER_EMAIL_ADDRESS));
    }
    if (connectTimeout > 0) {
        email.setSocketConnectionTimeout(connectTimeout);
    }
    if (soTimeout > 0) {
        email.setSocketTimeout(soTimeout);
    }

    // #1008 setting the subject via the setSubject(..) parameter.
    if (params.containsKey(EmailServiceConstants.SUBJECT)) {
        email.setSubject(params.get(EmailServiceConstants.SUBJECT));
    }

    return email;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:31,代码来源:EmailServiceImpl.java


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