本文整理汇总了Java中org.apache.commons.mail.Email.setSocketConnectionTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java Email.setSocketConnectionTimeout方法的具体用法?Java Email.setSocketConnectionTimeout怎么用?Java Email.setSocketConnectionTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.mail.Email
的用法示例。
在下文中一共展示了Email.setSocketConnectionTimeout方法的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;
}
示例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();
}
示例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());
}
示例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));
}
}
示例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;
}