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


Java EmailConstants类代码示例

本文整理汇总了Java中org.apache.commons.mail.EmailConstants的典型用法代码示例。如果您正苦于以下问题:Java EmailConstants类的具体用法?Java EmailConstants怎么用?Java EmailConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EmailConstants类属于org.apache.commons.mail包,在下文中一共展示了EmailConstants类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initializeMail

import org.apache.commons.mail.EmailConstants; //导入依赖的package包/类
/**
 * Creates a {@link HtmlEmail} object configured as per the AuthMe config
 * with the given email address as recipient.
 *
 * @param emailAddress the email address the email is destined for
 * @return the created HtmlEmail object
 * @throws EmailException if the mail is invalid
 */
public HtmlEmail initializeMail(String emailAddress) throws EmailException {
    String senderMail = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_ADDRESS))
        ? settings.getProperty(EmailSettings.MAIL_ACCOUNT)
        : settings.getProperty(EmailSettings.MAIL_ADDRESS);

    String senderName = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_SENDER_NAME))
        ? senderMail
        : settings.getProperty(EmailSettings.MAIL_SENDER_NAME);
    String mailPassword = settings.getProperty(EmailSettings.MAIL_PASSWORD);
    int port = settings.getProperty(EmailSettings.SMTP_PORT);

    HtmlEmail email = new HtmlEmail();
    email.setCharset(EmailConstants.UTF_8);
    email.setSmtpPort(port);
    email.setHostName(settings.getProperty(EmailSettings.SMTP_HOST));
    email.addTo(emailAddress);
    email.setFrom(senderMail, senderName);
    email.setSubject(settings.getProperty(EmailSettings.RECOVERY_MAIL_SUBJECT));
    email.setAuthentication(settings.getProperty(EmailSettings.MAIL_ACCOUNT), mailPassword);
    if (settings.getProperty(PluginSettings.LOG_LEVEL).includes(LogLevel.DEBUG)) {
        email.setDebug(true);
    }

    setPropertiesForPort(email, port);
    return email;
}
 
开发者ID:AuthMe,项目名称:AuthMeReloaded,代码行数:35,代码来源:SendMailSsl.java

示例2: sendEmail

import org.apache.commons.mail.EmailConstants; //导入依赖的package包/类
/**
   * Sends an email with a PDF attachment.
   * @throws TransportConfigurationException 
   * @throws EmailException 
   * @throws MessagingException 
   */
  public void sendEmail(String receipient, byte[] pdf) throws TransportConfigurationException, EmailException, MessagingException {
  	if(!configuration.isEnabled()) {
          throw new TransportConfigurationException("Email transport is not enabled in server configuration file!");
      }

      final MultiPartEmail email = new MultiPartEmail();
      email.setCharset(EmailConstants.UTF_8);
      

      if (Strings.isNullOrEmpty(configuration.getHostname())) {
          throw new TransportConfigurationException("No hostname configured for email transport while trying to send alert email!");
      } else {
          email.setHostName(configuration.getHostname());
      }
      email.setSmtpPort(configuration.getPort());
      if (configuration.isUseSsl()) {
          email.setSslSmtpPort(Integer.toString(configuration.getPort()));
      }

      if(configuration.isUseAuth()) {
          email.setAuthenticator(new DefaultAuthenticator(
                  Strings.nullToEmpty(configuration.getUsername()),
                  Strings.nullToEmpty(configuration.getPassword())
          ));
      }

      email.setSSLOnConnect(configuration.isUseSsl());
      email.setStartTLSEnabled(configuration.isUseTls());
      if (pluginConfig != null && !Strings.isNullOrEmpty(pluginConfig.getString("sender"))) {
          email.setFrom(pluginConfig.getString("sender"));
      } else {
          email.setFrom(configuration.getFromEmail());
      }
      
      
      email.setSubject("Graylog Aggregates Report");

      Calendar c = Calendar.getInstance();

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

      email.attach(new ByteArrayDataSource(pdf, "application/pdf"),
      	      "aggregates_report_" + df.format(c.getTime()) +".pdf", "Graylog Aggregates Report",
      	       EmailAttachment.ATTACHMENT);
              
      
      email.setMsg("Please find the report attached.");

      email.addTo(receipient);
              	
     	LOG.debug("sending report to " + email.getToAddresses().toString());
      	
     	email.send();
      
  }
 
开发者ID:cvtienhoven,项目名称:graylog-plugin-aggregates,代码行数:62,代码来源:ReportSender.java

示例3: apply

import org.apache.commons.mail.EmailConstants; //导入依赖的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.EmailConstants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。