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


Java DefaultAuthenticator类代码示例

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


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

示例1: doSend

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
private void doSend(String recipient, String sender, Set<String> cc, String subject, String content,
                    EmailAttachment... attachments) throws EmailException {
    HtmlEmail email = new HtmlEmail();
    email.setCharset("utf-8");
    for (EmailAttachment attachment : attachments) {
        email.attach(attachment);
    }
    email.setHostName(HOST);
    email.setSmtpPort(PORT);
    email.setAuthenticator(new DefaultAuthenticator(USER, PWD));
    email.setSSLOnConnect(USE_SSL);
    email.setSubject(subject);
    email.addTo(recipient);
    email.setFrom(String.format("Exam <%s>", SYSTEM_ACCOUNT));
    email.addReplyTo(sender);
    for (String addr : cc) {
        email.addCc(addr);
    }
    email.setHtmlMsg(content);
    if (USE_MOCK) {
        mockSending(email, content, attachments);
    } else {
        email.send();
    }
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:26,代码来源:EmailSenderImpl.java

示例2: sendEmail

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的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);
  }
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:17,代码来源:EmailSender.java

示例3: getHtmlEmail

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
private HtmlEmail getHtmlEmail( String hostName, int port, String username, String password, boolean tls,
    String sender )
    throws EmailException
{
    HtmlEmail email = new HtmlEmail();
    email.setHostName( hostName );
    email.setFrom( sender, customizeTitle( DEFAULT_FROM_NAME ) );
    email.setSmtpPort( port );
    email.setStartTLSEnabled( tls );

    if ( username != null && password != null )
    {
        email.setAuthenticator( new DefaultAuthenticator( username, password ) );
    }

    return email;
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:18,代码来源:EmailMessageSender.java

示例4: getHtmlEmail

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
private HtmlEmail getHtmlEmail( String hostName, int port, String username, String password, boolean tls, String sender )
    throws EmailException
{
    HtmlEmail email = new HtmlEmail();
    email.setHostName( hostName );
    email.setFrom( defaultIfEmpty( sender, FROM_ADDRESS ), customizeTitle( DEFAULT_FROM_NAME ) );
    email.setSmtpPort( port );
    email.setStartTLSEnabled( tls );

    if ( username != null && password != null )
    {
        email.setAuthenticator( new DefaultAuthenticator( username, password ) );
    }

    return email;
}
 
开发者ID:ehatle,项目名称:AgileAlligators,代码行数:17,代码来源:EmailMessageSender.java

示例5: sendEmail

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
public void sendEmail() {
	HtmlEmail email = new HtmlEmail();
	try {
		email.setHostName(emailHostName);
		email.setSmtpPort(smtpPort);
		email.setAuthenticator(new DefaultAuthenticator(emailLogin,
				emailPassword));
		email.setSSLOnConnect(emailSSL);
		email.setStartTLSEnabled(startTLS);
		email.setFrom(emailSender);
		email.setSubject(title);
		email.setHtmlMsg(htmlMessage);
		email.addTo(emailRecipient);
		email.send();
		System.out.println("Email sent: " + title);
	} catch (EmailException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:RobCubed,项目名称:ShipworksWeeklyReports,代码行数:21,代码来源:Email.java

示例6: sendEmail

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
/** Sends email according to the provided config. */
private static void sendEmail(SmtpConfiguration config, HtmlEmail email, String subject,
    String fromAddress, String toAddress) throws EmailException {
  if (config != null) {
    email.setSubject(subject);
    LOG.info("Sending email to {}", toAddress);
    email.setHostName(config.getSmtpHost());
    email.setSmtpPort(config.getSmtpPort());
    if (config.getSmtpUser() != null && config.getSmtpPassword() != null) {
      email.setAuthenticator(
          new DefaultAuthenticator(config.getSmtpUser(), config.getSmtpPassword()));
      email.setSSLOnConnect(true);
    }
    email.setFrom(fromAddress);
    for (String address : toAddress.split(EMAIL_ADDRESS_SEPARATOR)) {
      email.addTo(address);
    }
    email.send();
    LOG.info("Email sent with subject [{}] to address [{}]!", subject, toAddress);
  } else {
    LOG.error("No email config provided for email with subject [{}]!", subject);
  }
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:24,代码来源:EmailHelper.java

示例7: sendWithHtml

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
@Override
public void sendWithHtml(String recipient, String subject, String content) throws SendMailException {
	Assert.hasText(recipient);
	Assert.hasText(subject);
	Assert.hasText(content);
	
	HtmlEmail email = new HtmlEmail();
	email.setHostName(host);
	email.setAuthenticator(new DefaultAuthenticator(loginName, loginPassword));
	email.setSmtpPort(port);
	email.setTLS(tls);

	try {
		email.setCharset("UTF-8"); // specify the charset.
		email.setFrom(fromAddress, fromName);
		email.setSubject(subject);
		email.setHtmlMsg(content);
		//email.setMsg(""); // can set plain text either
		email.addTo(recipient);
		email.send();
	} catch (EmailException e) {
		throw new SendMailException(
				String.format("Failed to send mail to %s.", recipient), e);
	}
}
 
开发者ID:ivarptr,项目名称:clobaframe,代码行数:26,代码来源:SmtpMailSender.java

示例8: send

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
/**
 * Send email with subject and message body.
 * @param subject the email subject.
 * @param body the email body.
 */
public void send(String subject, String body) {
    try {
        HtmlEmail email = new HtmlEmail();
        email.setHostName(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_HOST, "localhost"));
        email.setSmtpPort(configuration.getInt(CONFKEY_REPORTS_MAILER_SMTP_PORT, 465));
        email.setAuthenticator(new DefaultAuthenticator(
            configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_USER, "anonymous"),
            configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_PASS, "guest")
        ));
        email.setStartTLSEnabled(false);
        email.setSSLOnConnect(configuration.getBoolean(CONFKEY_REPORTS_MAILER_SMTP_SSL, true));
        email.setFrom(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_FROM, ""));
        email.setSubject(subject);
        email.setHtmlMsg(body);
        String[] receivers = configuration.getStringArray(CONFKEY_REPORTS_MAILER_SMTP_TO);
        for (String receiver : receivers) {
            email.addTo(receiver);
        }
        email.send();
        LOG.info("Report sent with email to " + email.getToAddresses().toString() + " (\"" + subject + "\")");
    } catch (EmailException e) {
        LOG.error(e.getMessage(), e);
    }
}
 
开发者ID:dma-ais,项目名称:AisAbnormal,代码行数:30,代码来源:ReportMailer.java

示例9: send

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
protected void send(String mailAddress, String title, String content) {
    if (StringUtils.isBlank(mailAddress)) {
        return;
    }

    try {
        Email email = new HtmlEmail();
        email.setHostName(hostname);
        email.setAuthenticator(new DefaultAuthenticator(username, password));
        email.setSmtpPort(port);
        email.setFrom(from, fromname);
        email.setSubject(title);
        email.setMsg(content);
        email.addTo(mailAddress.split(mailAddressEndSeparator));
        email.send();
    } catch (Exception e) {
        logger.error("Send Mail Error", e);
    }
}
 
开发者ID:XiaoMi,项目名称:shepher,代码行数:20,代码来源:GeneralMailSender.java

示例10: createEmail

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的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;
}
 
开发者ID:dmart28,项目名称:gcplot,代码行数:24,代码来源:SMTPMailProvider.java

示例11: getHtmlEmail

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
public HtmlEmail getHtmlEmail() {
    HtmlEmail email = new HtmlEmail();

    email.setHostName(hostname);
    email.setSmtpPort(port);

    if (username != null && password != null && !username.isEmpty()) {
        email.setAuthenticator(new DefaultAuthenticator(username, password));
    }

    email.setSSLOnConnect(sslOnConnect);
    email.setStartTLSEnabled(startTslEnabled);
    email.setStartTLSRequired(requireTsl);

    return email;
}
 
开发者ID:UKHomeOffice,项目名称:email-api,代码行数:17,代码来源:HtmlEmailFactoryImpl.java

示例12: send

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
@RequestMapping("/send")
public HttpEntity<Void> send() throws EmailException {

  // An unlucky fool hardcoded some smtp code here.
  Email email = new SimpleEmail();
  email.setHostName("localhost");
  email.setSmtpPort(3025);
  email.setAuthenticator(new DefaultAuthenticator("username", "password"));
  email.setFrom("[email protected]");
  email.setSubject("TestMail");
  email.setMsg("This is a test mail ... :-)");
  email.addTo("[email protected]");
  email.send();

  return ResponseEntity.ok().build();
}
 
开发者ID:AndreasKl,项目名称:java-classic-playground,代码行数:17,代码来源:SendMailController.java

示例13: sendNormalEmail

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
/**
 * Send a verification email to the user's email account if exist.
 * 
 * @param user
 */
public void sendNormalEmail(String subject, String content, String[] addresses ) {
	if ( StringUtil.checkNotEmpty(subject) && StringUtil.checkNotEmpty(content) ) {
		try {
			String emailSmtp = GameDataManager.getInstance().getGameDataAsString(GameDataKey.EMAIL_SMTP, "mail.xinqihd.com");
			SimpleEmail email = new SimpleEmail();
			email.setHostName(emailSmtp);
			email.setAuthenticator(new DefaultAuthenticator(EMAIL_FROM, "[email protected]"));
			email.setFrom(EMAIL_FROM);
			email.setSubject(subject);
			email.setMsg(content);
			email.setCharset("GBK");
			for ( String address : addresses) {
				if ( StringUtil.checkNotEmpty(address) ) {
					email.addTo(address);
				}
			}
			email.send();
		} catch (EmailException e) {
			logger.debug("Failed to send normal email", e);
		}
	}
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:28,代码来源:EmailManager.java

示例14: init

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的package包/类
/**
 * Initializes the mail sender by looking up configured values needed for accessing an SMTP host.
 * <p>
 * @throws SdiException
 */
public void init() throws SdiException
{
    myDryRun = ConfigUtils.getBooleanProperty( myEnv, SdiMainProperties.KEY_DRYRUN, false );

    try
    {
        myHost = myEnv.getRequiredProperty( MailProperties.KEY_HOST );
        myPort = ConfigUtils.getIntProperty( myEnv, MailProperties.KEY_PORT, 25 );
        myAuthenticator = new DefaultAuthenticator( myEnv.getProperty( MailProperties.KEY_SMTP_USER ),
                                                    myEnv.getProperty( MailProperties.KEY_SMTP_PASSWORD ) );
        mySslOnConnect = ConfigUtils.getBooleanProperty( myEnv, MailProperties.KEY_SSL_ON_CONNECT, false );
        myStartTlsRequired = ConfigUtils.getBooleanProperty( myEnv,
                                                             MailProperties.KEY_START_TLS_REQUIRED, false );
        mySenderAddress = myEnv.getRequiredProperty( MailProperties.KEY_SENDER_ADDRESS );
        myContentType = myEnv.getProperty( MailProperties.KEY_SENDER_ADDRESS, "text/plain" );

       myLog.info( "Mail-Configuration: "
                   + "\n    myHost            : " + myHost
                   + "\n    myPort            : " + myPort
                   + "\n    mySslOnConnect    : " + mySslOnConnect
                   + "\n    myStartTlsRequired: " + myStartTlsRequired
                   + "\n    mySenderAddress   : " + mySenderAddress
                   + "\n    myContentType     : " + myContentType

                   );
    }
    catch ( Throwable t )
    {
        throw new SdiException( "Problems initializing the mail parameters",
                                t,
                                SdiException.EXIT_CODE_CONFIG_ERROR );
    }

}
 
开发者ID:heribender,项目名称:SocialDataImporter,代码行数:40,代码来源:MailSenderDefault.java

示例15: setupEmail

import org.apache.commons.mail.DefaultAuthenticator; //导入依赖的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()));
	}
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:20,代码来源:EmailServiceImpl.java


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