當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。