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


Java Email.setAuthenticator方法代码示例

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


在下文中一共展示了Email.setAuthenticator方法的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);
  }
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:17,代码来源:EmailSender.java

示例2: send

import org.apache.commons.mail.Email; //导入方法依赖的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

示例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;
}
 
开发者ID:dmart28,项目名称:gcplot,代码行数:24,代码来源:SMTPMailProvider.java

示例4: send

import org.apache.commons.mail.Email; //导入方法依赖的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

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

示例6: setupEmail

import org.apache.commons.mail.Email; //导入方法依赖的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

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

示例8: sendMail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
@Override
public void sendMail(String recipient, String subject, String content) throws FablabException {
	try {
		Email email = new SimpleEmail();
		email.setHostName("localhost");
		email.setSmtpPort(25);
		email.setAuthenticator(new DefaultAuthenticator("test", "test"));
		email.setFrom("[email protected]");
		email.setSubject(subject);
		email.setMsg(content);
		email.addTo(recipient);
		email.send();
	} catch (EmailException ex) {
		LOG.error("Canont send mail ", ex);
	}
}
 
开发者ID:romainGuiet,项目名称:fablab-web,代码行数:17,代码来源:MailServiceImpl.java

示例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;
	}
}
 
开发者ID:amdiaosi,项目名称:nutzWx,代码行数:23,代码来源:MailServiceImpl.java

示例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;
}
 
开发者ID:dangduc,项目名称:consul-notif,代码行数:17,代码来源:EmailService.java

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

示例12: send

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
@Override
public void send(String recipient, String subject, String content) throws SendMailException {
	Assert.hasText(recipient);
	Assert.hasText(subject);
	Assert.hasText(content);
	
	Email email = new SimpleEmail();
	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.setMsg(content);
		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

示例13: post

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
@Override
public String post(Email message) {
	
	try {
		message.setSmtpPort(587);
	    message.setAuthenticator(new DefaultAuthenticator("[email protected]", "3cWaN2jGhEbAAT"));
	    message.setDebug(false);
	    message.setHostName("smtp.gmail.com");
	    message.setFrom("The Job Announcer <[email protected]>");
	    message.setTLS(true);
	    message.send();
		log.info("Mailed Notification with subject '" + message.getSubject() + "'.");
		return message.toString();
	} catch (EmailException e) {
	    log.warning("Failed to mail Notification with subject '" + message.getSubject() + "'.");
		log.throwing(getClass().getName(), "post", e);
		throw new RuntimeException(e);
	}
	
}
 
开发者ID:plexiti,项目名称:the-job-announcement,代码行数:21,代码来源:MailingServiceImpl.java

示例14: 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);
}
 
开发者ID:CROW-NDOV,项目名称:displaydirect,代码行数:16,代码来源:EmailUtil.java

示例15: initializeEmail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private void initializeEmail(final Email email) throws EmailException {
	email.setSocketConnectionTimeout(configuration.getInt("email.connection.timeout", Defaults.SOCKET_CONNECTION_TIMEOUT));
	email.setSocketTimeout(configuration.getInt("email.socket.timeout", Defaults.SOCKET_TIMEOUT));
	email.setStartTLSEnabled(configuration.getBoolean("email.starttls.enabled", Defaults.STARTTLS_ENABLED));
	email.setStartTLSRequired(configuration.getBoolean("email.starttls.required", Defaults.STARTTLS_REQUIRED));
	email.setSSLCheckServerIdentity(configuration.getBoolean("email.ssl.identity", Defaults.SSL_IDENTITY));
	email.setSSLOnConnect(configuration.getBoolean("email.ssl.connect", Defaults.SSL_CONNECT));
	email.setSmtpPort(configuration.getInt("email.port", Defaults.PORT));
	email.setSslSmtpPort(Integer.toString(configuration.getInt("email.ssl.port", Defaults.SSL_PORT)));

	email.setHostName(configuration.getString(CFG_KEY_EMAIL_HOST));

	// Authentication
	if (!configuration.getString(CFG_KEY_EMAIL_USERNAME, true).isEmpty() && !configuration.getString(CFG_KEY_EMAIL_PASSWORD, true).isEmpty()) {
		email.setAuthenticator(new DefaultAuthenticator(configuration.getString(CFG_KEY_EMAIL_USERNAME), configuration.getString(CFG_KEY_EMAIL_PASSWORD)));
	}

	// Sender
	if (configuration.getString(CFG_KEY_EMAIL_FROM_NAME, true).isEmpty()) {
		email.setFrom(configuration.getString(CFG_KEY_EMAIL_FROM_ADDRESS));
	}
	else {
		email.setFrom(configuration.getString(CFG_KEY_EMAIL_FROM_ADDRESS), configuration.getString(CFG_KEY_EMAIL_FROM_NAME));
	}

	// Recipients
	if (!configuration.getString(CFG_KEY_EMAIL_TO_ADDRESSES, true).isEmpty()) {
		email.addTo(configuration.getString(CFG_KEY_EMAIL_TO_ADDRESSES).split(EMAIL_ADDRESSES_SPLIT_REGEX));
	}
	if (!configuration.getString(CFG_KEY_EMAIL_CC_ADDRESSES, true).isEmpty()) {
		email.addCc(configuration.getString(CFG_KEY_EMAIL_CC_ADDRESSES).split(EMAIL_ADDRESSES_SPLIT_REGEX));
	}
	if (!configuration.getString(CFG_KEY_EMAIL_BCC_ADDRESSES, true).isEmpty()) {
		email.addBcc(configuration.getString(CFG_KEY_EMAIL_BCC_ADDRESSES).split(EMAIL_ADDRESSES_SPLIT_REGEX));
	}
}
 
开发者ID:Albertus82,项目名称:RouterLogger,代码行数:37,代码来源:EmailSender.java


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