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


Java Email.setAuthentication方法代码示例

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


在下文中一共展示了Email.setAuthentication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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());
    }
}
 
开发者ID:flyersa,项目名称:MuninMX,代码行数:27,代码来源:Methods.java

示例3: setMailServerProperties

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
protected void setMailServerProperties(Email email) {
  ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();

  String host = processEngineConfiguration.getMailServerHost();
  if (host == null) {
    throw new ActivitiException("Could not send email: no SMTP host is configured");
  }
  email.setHostName(host);

  int port = processEngineConfiguration.getMailServerPort();
  email.setSmtpPort(port);

  String user = processEngineConfiguration.getMailServerUsername();
  String password = processEngineConfiguration.getMailServerPassword();
  if (user != null && password != null) {
    email.setAuthentication(user, password);
  }
}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:19,代码来源:MailActivityBehavior.java

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

示例5: 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);
	}
}
 
开发者ID:resto-tesis,项目名称:resto-tesis,代码行数:20,代码来源:CorreoServicio.java

示例6: setMailServerProperties

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
protected void setMailServerProperties(Email email) {
  ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();

  String host = processEngineConfiguration.getMailServerHost();
  if (host == null) {
    throw new ActivitiException("Could not send email: no SMTP host is configured");
  }
  email.setHostName(host);

  int port = processEngineConfiguration.getMailServerPort();
  email.setSmtpPort(port);

  email.setTLS(processEngineConfiguration.getMailServerUseTLS());

  String user = processEngineConfiguration.getMailServerUsername();
  String password = processEngineConfiguration.getMailServerPassword();
  if (user != null && password != null) {
    email.setAuthentication(user, password);
  }
}
 
开发者ID:iotsap,项目名称:FiWare-Template-Handler,代码行数:21,代码来源:MailActivityBehavior.java

示例7: setMailServerProperties

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
protected void setMailServerProperties(Email email) {
  ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();

  String host = processEngineConfiguration.getMailServerHost();
  if (host == null) {
    throw new ActivitiException("Could not send email: no SMTP host is configured");
  }
  email.setHostName(host);

  int port = processEngineConfiguration.getMailServerPort();
  email.setSmtpPort(port);

  email.setSSL(processEngineConfiguration.getMailServerUseSSL());
  email.setTLS(processEngineConfiguration.getMailServerUseTLS());

  String user = processEngineConfiguration.getMailServerUsername();
  String password = processEngineConfiguration.getMailServerPassword();
  if (user != null && password != null) {
    email.setAuthentication(user, password);
  }
}
 
开发者ID:springvelocity,项目名称:xbpm5,代码行数:22,代码来源:MailActivityBehavior.java

示例8: setMailServerProperties

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
protected void setMailServerProperties(Email email) {
  ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();

  String host = processEngineConfiguration.getMailServerHost();
  ensureNotNull("Could not send email: no SMTP host is configured", "host", host);
  email.setHostName(host);

  int port = processEngineConfiguration.getMailServerPort();
  email.setSmtpPort(port);

  email.setTLS(processEngineConfiguration.getMailServerUseTLS());

  String user = processEngineConfiguration.getMailServerUsername();
  String password = processEngineConfiguration.getMailServerPassword();
  if (user != null && password != null) {
    email.setAuthentication(user, password);
  }
}
 
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:19,代码来源:MailActivityBehavior.java

示例9: 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;
}
 
开发者ID:RoboZonky,项目名称:robozonky,代码行数:14,代码来源:AbstractEmailingListener.java

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

示例11: sendEmail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
/**
 * A general method for sending emails.
 *
 * @param state a {@link State} object containing configuration properties
 * @param subject email subject
 * @param message email message
 * @throws EmailException if there is anything wrong sending the email
 */
public static void sendEmail(State state, String subject, String message) throws EmailException {
  Email email = new SimpleEmail();
  email.setHostName(state.getProp(ConfigurationKeys.EMAIL_HOST_KEY, ConfigurationKeys.DEFAULT_EMAIL_HOST));
  if (state.contains(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)) {
    email.setSmtpPort(state.getPropAsInt(ConfigurationKeys.EMAIL_SMTP_PORT_KEY));
  }
  email.setFrom(state.getProp(ConfigurationKeys.EMAIL_FROM_KEY));
  if (state.contains(ConfigurationKeys.EMAIL_USER_KEY) && state.contains(ConfigurationKeys.EMAIL_PASSWORD_KEY)) {
    email.setAuthentication(state.getProp(ConfigurationKeys.EMAIL_USER_KEY),
        PasswordManager.getInstance(state).readPassword(state.getProp(ConfigurationKeys.EMAIL_PASSWORD_KEY)));
  }
  Iterable<String> tos =
      Splitter.on(',').trimResults().omitEmptyStrings().split(state.getProp(ConfigurationKeys.EMAIL_TOS_KEY));
  for (String to : tos) {
    email.addTo(to);
  }

  String hostName;
  try {
    hostName = InetAddress.getLocalHost().getHostName();
  } catch (UnknownHostException uhe) {
    LOGGER.error("Failed to get the host name", uhe);
    hostName = "unknown";
  }

  email.setSubject(subject);
  String fromHostLine = String.format("This email was sent from host: %s%n%n", hostName);
  email.setMsg(fromHostLine + message);
  email.send();
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:39,代码来源:EmailUtils.java

示例12: createEmail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private Email createEmail(final String title, final String body) throws EmailException {
  Email email = new SimpleEmail();
  email.setHostName(host);
  email.setAuthentication(username, password);
  email.setSmtpPort(port);
  email.setSSLOnConnect(useSsl);
  email.setFrom(checkNotNullOrEmpty(from));
  email.addTo(checkNotNullOrEmpty(to));
  email.setSubject(title);
  email.setMsg(body);
  return email;
}
 
开发者ID:melphi,项目名称:onplan,代码行数:13,代码来源:SmtpNotificationChannel.java

示例13: 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) throws IOException {

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

    Email email = new HtmlEmail();
    email.setHostName(host);
    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");
        ((HtmlEmail) email).setHtmlMsg(content);
        email.send();
        email.getMailSession();

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

    return true;
}
 
开发者ID:KylinOLAP,项目名称:Kylin,代码行数:42,代码来源:MailService.java

示例14: sendsimpleEmail2

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
public void sendsimpleEmail2(Email email, String userName, String password,
		String subject, String simpleEmailBody, String from, String to,
		String cc, String bcc) throws EmailException {

	// 创建SimpleEmail对象

	// 显示调试信息用于IED中输出
	email.setDebug(true);

	// 设置发送电子邮件的邮件服务器
	email.setHostName("smtp.gmail.com");

	// 邮件服务器是否使用ssl加密方式gmail就是,163就不是)
	email.setSSL(Boolean.TRUE);

	// 设置smtp端口号(需要查看邮件服务器的说明ssl加密之后端口号是不一样的)
	email.setSmtpPort(465);

	// 设置发送人的账号/密码
	email.setAuthentication(userName, password);

	// 显示的发信人地址,实际地址为gmail的地址
	email.setFrom(from);
	// 设置发件人的地址/称呼
	// email.setFrom("[email protected]", "发送人");

	// 收信人地址
	email.addTo(to);
	// 设置收件人的账号/称呼)
	// email.addTo("[email protected]", "收件人");

	// 多个抄送地址
	StrTokenizer stokenCC = new StrTokenizer(cc.trim(), ";");
	// 开始逐个抄送地址
	for (int i = 0; i < stokenCC.getTokenArray().length; i++) {
		email.addCc((String) stokenCC.getTokenArray()[i]);
	}

	// 多个密送送地址
	StrTokenizer stokenBCC = new StrTokenizer(bcc.trim(), ";");
	// 开始逐个抄送地址
	for (int i = 0; i < stokenBCC.getTokenArray().length; i++) {
		email.addBcc((String) stokenBCC.getTokenArray()[i]);
	}

	// Set the charset of the message.
	email.setCharset("UTF-8");

	email.setSentDate(new Date());

	// 设置标题,但是不能设置编码,commons 邮件的缺陷
	email.setSubject(subject);

	// 设置邮件正文
	email.setMsg(simpleEmailBody);

	// 就是send发送
	email.send();

	// 这个是我自己写的。
	System.out.println("The SimpleEmail send sucessful!");

}
 
开发者ID:h819,项目名称:spring-boot,代码行数:64,代码来源:SendEmaiWithGmail.java

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


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