本文整理汇总了Java中org.apache.commons.mail.Email.setSslSmtpPort方法的典型用法代码示例。如果您正苦于以下问题:Java Email.setSslSmtpPort方法的具体用法?Java Email.setSslSmtpPort怎么用?Java Email.setSslSmtpPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.mail.Email
的用法示例。
在下文中一共展示了Email.setSslSmtpPort方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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());
}
示例3: setupEmail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private void setupEmail(Email email) throws EmailException {
email.setHostName(getHostName());
email.setSslSmtpPort(getSmtpPort());
email.setFrom(getReplyAddress(), getReplyName());
if (StringUtils.isNotBlank(useSsl)) {
email.setSSL(Boolean.valueOf(getUseSsl()));
email.setSslSmtpPort(getSslPort());
}
if (StringUtils.isNotBlank(useTls)) {
email.setTLS(Boolean.valueOf(getUseTls()));
}
// use authentication if configured
if (StringUtils.isNotBlank(getAuthenticationUserName())) {
email.setAuthenticator(new DefaultAuthenticator(getAuthenticationUserName(), getAuthenticationPassword()));
}
}
示例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: 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());
}
示例6: addStandardDetails
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private void addStandardDetails(Email email) throws EmailException {
email.setHostName(smtpHost);
email.setSmtpPort(smtpPort);
email.setAuthenticator(new DefaultAuthenticator(smtpUsername, smtpPassword));
email.setSSLOnConnect(smtpSsl);
// If we're using SSL, then the port specified will be the port to use for sSmtp also
if (smtpSsl) {
email.setSslSmtpPort(Integer.toString(smtpPort));
}
}
示例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;
}
示例8: 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;
}