本文整理汇总了Java中org.apache.commons.mail.Email.setSSLOnConnect方法的典型用法代码示例。如果您正苦于以下问题:Java Email.setSSLOnConnect方法的具体用法?Java Email.setSSLOnConnect怎么用?Java Email.setSSLOnConnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.mail.Email
的用法示例。
在下文中一共展示了Email.setSSLOnConnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendEmail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
public void sendEmail(final EmailData emailData) {
try {
Email email = new SimpleEmail();
email.setHostName(smtpServer);
email.setSmtpPort(smtpPort);
email.setAuthenticator(new DefaultAuthenticator(username, password));
email.setSSLOnConnect(secure);
email.setFrom(emailData.getAddressFrom());
email.setSubject(emailData.getSubject());
email.setMsg(emailData.getMessageContent());
email.addTo(emailData.getAddressTo());
email.send();
} catch (org.apache.commons.mail.EmailException e) {
throw new EmailException(e);
}
}
示例2: 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);
}
}
示例3: 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;
}
示例4: sendMail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private static void sendMail(String title, String message, String emailaddy) {
try {
Email email = new SimpleEmail();
email.setHostName(p.getProperty("mailserver.host"));
email.setSmtpPort(Integer.parseInt(p.getProperty("mailserver.port")));
if(p.getProperty("mailserver.useauth").equals("true"))
{
email.setAuthentication(p.getProperty("mailserver.user"), p.getProperty("mailserver.pass"));
}
if(p.getProperty("mailserver.usessl").equals("true"))
{
email.setSSLOnConnect(true);
}
else
{
email.setSSLOnConnect(false);
}
email.setFrom(p.getProperty("mailserver.from"));
email.setSubject("[MuninMX] " + title);
email.setMsg(message);
email.addTo(emailaddy);
email.send();
} catch (Exception ex) {
logger.warn("Unable to send Mail: " + ex.getLocalizedMessage());
}
}
示例5: 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());
}
示例6: send
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
@NotInServiceMenu
@Named("Enviar Correo")
public String send(final Cliente unCliente, final Oferta unaOferta) {
try {
Email email = new SimpleEmail();
email.setHostName("smtp.gmail.com");
email.setSmtpPort(465);
email.setAuthentication("[email protected]", "modica1234");
email.setSSLOnConnect(true);
email.setFrom("[email protected]", "Resto Tesis");
email.setSubject("Ofertas para esta Semana!");
email.setMsg(printing.ofertaToText(unaOferta));
email.addTo(unCliente.getCorreo());
return email.send();
} catch (EmailException e) {
throw new servicio.correo.CorreoException(e.getMessage(), e);
}
}
示例7: 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);
}
});
}
}
示例8: send
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
@Override
protected void send(EmailConfigDTO configDTO, ToSend message) {
try {
Email email = new SimpleEmail();
email.setHostName(server);
email.setSmtpPort(port);
email.setAuthenticator(new DefaultAuthenticator(login, password));
email.setSSLOnConnect(true);
email.setFrom(from);
email.setSubject(message.getSubject());
email.setMsg(message.getBody());
email.addTo(configDTO.getRecipient());
email.send();
} catch (EmailException ex) {
LOGGER.error("Send E-mail exception.", ex);
}
}
示例9: send
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
public boolean send(String to, String subject, String tpl, Context ctx) {
Email email = new SimpleEmail();
email.setHostName(config.get("mail.host"));
email.setAuthenticator(new DefaultAuthenticator(config.get("mail.user"), config.get("mail.passwd")));
if (config.getInt("mail.ssl", 0) == 1) {
email.setSSLOnConnect(true);
email.setSmtpPort(config.getInt("mail.port", 465));
} else {
email.setSmtpPort(config.getInt("mail.port", 25));
}
try {
email.setFrom(config.get("mail.from"));
email.setSubject("["+config.get("mail.suject.prefix", "Test") + "] " + subject);
email.setMsg(Segments.create(tpl).render(ctx).toString());
email.addTo(to);
email.send();
return true;
} catch (EmailException e) {
log.info("Send email fail", e);
return false;
}
}
示例10: createEmail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private Email createEmail() throws EmailException {
if (config == null) {
throw new EmailException("cannot create email without config");
}
Email email = new SimpleEmail();
email.setHostName(config.getSmtpServer());
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator(config.getSmtpUser(), config.getSmtpPass()));
email.setSSLOnConnect(true);
email.setFrom(config.getNotifSenderEmail());
email.addTo(config.getNotifRecipientEmail());
return email;
}
示例11: sendMail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
public static void sendMail(MailConf mailConf, String mailLine) throws EmailException {
Email email = new SimpleEmail();
email.setHostName(mailConf.getSmtp_server());
email.setSmtpPort(mailConf.getSmtp_port());
email.setAuthenticator(new DefaultAuthenticator(mailConf.getUser_name(), mailConf.getPassword()));
email.setSSLOnConnect(mailConf.isSmtp_ssl_flag());
email.setFrom(mailConf.getSrc_mail_adress());
email.setSubject(Constant.SOFTWARE_NAME + " " + System.currentTimeMillis());
email.setContent(mailLine, "text/plain; charset=ISO-2022-JP");
email.setCharset("ISO-2022-JP");
// try {
// email.setMsg(new String(mailLine.getBytes("iso-2022-jp")));
// } catch (UnsupportedEncodingException e) {
// // TODO 自動生成された catch ブロック
// e.printStackTrace();
// }
email.addTo(mailConf.getDest_mail_adress());
email.send();
}
示例12: setupEmail
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private static void setupEmail(Email mail, String to, String subject, String template, Map<String, Object> body) throws EmailException {
mail.setHostName(Configuration.getSmtpHostname());
mail.setFrom(Configuration.getSmtpFrom(), "DisplayDirect");
if (Configuration.getSmtpUsername() != null && Configuration.getSmtpPassword() != null) {
mail.setAuthenticator(new DefaultAuthenticator(Configuration.getSmtpUsername(), Configuration.getSmtpPassword()));
}
if (Configuration.getSmtpSsl()) {
mail.setSSLOnConnect(true); // Setting this changes the port to 465
}
mail.setSmtpPort(Configuration.getSmtpPort());
mail.addReplyTo(Configuration.getSmtpReplyTo(), "DisplayDirect");
mail.setSubject(subject);
addEmailTo(mail, to);
}
示例13: main
import org.apache.commons.mail.Email; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSSLOnConnect(false); //OK
Email email2 = new SimpleEmail();
email2.setHostName("smtp2.googlemail.com");
email2.setSSLOnConnect(true); //BAD
//email2.setSmtpPort(465);
//email2.setAuthenticator(new DefaultAuthenticator("username", "password"));
//email2.setFrom("[email protected]");
//email2.setSubject("TestMail");
//email2.setMsg("This is a test mail ... :-)");
//email2.addTo("[email protected]");
//email2.send();
MultiPartEmail emailMulti = new MultiPartEmail();
emailMulti.setHostName("mail.myserver.com");
emailMulti.setSSLOnConnect(true); //BAD
HtmlEmail htmlEmail = new HtmlEmail();
htmlEmail.setHostName("mail.myserver.com");
htmlEmail.setSSLOnConnect(true); //BAD
ImageHtmlEmail imageEmail = new ImageHtmlEmail();
imageEmail.setHostName("mail.myserver.com");
imageEmail.setSSLOnConnect(true);
imageEmail.setSSLCheckServerIdentity(true); //OK
ImageHtmlEmail imageEmail2 = new ImageHtmlEmail();
imageEmail2.setHostName("mail2.myserver.com");
imageEmail2.setSSLCheckServerIdentity(true); //OK - reversed order
imageEmail2.setSSLOnConnect(true);
ImageHtmlEmail imageEmail3 = new ImageHtmlEmail();
imageEmail3.setHostName("mail3.myserver.com");
imageEmail3.setSSLOnConnect(true); //BAD
}
示例14: 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;
}
示例15: 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());
}