當前位置: 首頁>>代碼示例>>Java>>正文


Java HtmlEmail.setAuthenticator方法代碼示例

本文整理匯總了Java中org.apache.commons.mail.HtmlEmail.setAuthenticator方法的典型用法代碼示例。如果您正苦於以下問題:Java HtmlEmail.setAuthenticator方法的具體用法?Java HtmlEmail.setAuthenticator怎麽用?Java HtmlEmail.setAuthenticator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.mail.HtmlEmail的用法示例。


在下文中一共展示了HtmlEmail.setAuthenticator方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doSend

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的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: getHtmlEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的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

示例3: getHtmlEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的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

示例4: sendEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的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

示例5: sendEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的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

示例6: sendWithHtml

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的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

示例7: send

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的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

示例8: sendHtmlEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
private void sendHtmlEmail() throws MangooMailerException {
    Config config = Application.getInstance(Config.class);
    try {
        HtmlEmail htmlEmail = new HtmlEmail();
        htmlEmail.setCharset(Default.ENCODING.toString());
        htmlEmail.setHostName(config.getSmtpHost());
        htmlEmail.setSmtpPort(config.getSmtpPort());
        htmlEmail.setAuthenticator(getDefaultAuthenticator());
        htmlEmail.setSSLOnConnect(config.isSmtpSSL());
        htmlEmail.setFrom(this.from);
        htmlEmail.setSubject(this.subject);
        htmlEmail.setHtmlMsg(render());
        
        for (String recipient : this.recipients) {
            htmlEmail.addTo(recipient);
        }
        
        for (String cc : this.ccRecipients) {
            htmlEmail.addCc(cc);
        }
        
        for (String bcc : this.bccRecipients) {
            htmlEmail.addBcc(bcc);
        }
        
        for (File file : this.files) {
            htmlEmail.attach(file);
        }
        
        htmlEmail.send();
    } catch (EmailException | MangooTemplateEngineException e) {
        throw new MangooMailerException(e);
    } 
}
 
開發者ID:svenkubiak,項目名稱:mangooio,代碼行數:35,代碼來源:Mail.java

示例9: getHtmlEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的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

示例10: forgetPassword

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
/**
 * Process the forget password scenario
 * @return
 */
public boolean forgetPassword(String roleName, IoSession session) {
	String message = Text.text("forget.fail");
	boolean result = false;
	if ( StringUtil.checkNotEmpty(roleName) ) {
		Account account = AccountManager.getInstance().queryAccountByName(roleName);
		//User user = UserManager.getInstance().queryUserByRoleName(roleName);
		//if ( user != null ) {
		if ( account != null ) {
			String emailAddress = account.getEmail();
			if ( StringUtil.checkValidEmail(emailAddress) ) {
				try {
					Jedis jedis = JedisFactory.getJedisDB();
					String key = StringUtil.concat(Constant.FORGET_PASS_KEY, roleName);
					String tempPassword = jedis.get(key);
					if ( tempPassword != null ) {
						message = Text.text("forget.ok");
						result = true;
					} else {
						String emailSmtp = GameDataManager.getInstance().getGameDataAsString(GameDataKey.EMAIL_SMTP, "xinqihd.com");
						HtmlEmail email = new HtmlEmail();
						email.setHostName(emailSmtp);
						email.setAuthenticator(new DefaultAuthenticator(EMAIL_FROM, "[email protected]"));
						email.setFrom(EMAIL_FROM);
						String subject = Text.text("forget.subject");
						tempPassword = String.valueOf(System.currentTimeMillis()%10000);
						String displayRoleName = UserManager.getDisplayRoleName(account.getUserName());
						String content = Text.text("forget.content", displayRoleName, tempPassword);
						email.setSubject(subject);
						email.setHtmlMsg(content);
						email.setCharset("GBK");
						email.addTo(emailAddress);
						email.send();

						jedis.set(key, tempPassword);
						jedis.expire(key, Constant.HALF_HOUR_SECONDS);

						message = Text.text("forget.ok");
						result = true;
					}
				} catch (EmailException e) {
					logger.error("Failed to send email to user's email: {}", emailAddress);
					logger.debug("EmailException", e);
				}
			} else {
				message = Text.text("forget.noemail");
			}
			//StatClient.getIntance().sendDataToStatServer(user, StatAction.ForgetPassword, emailAddress, result);
		} else {
			message = Text.text("forget.nouser");	
		}
	} else {
		message = Text.text("forget.noname");
	}
	
	BseSysMessage.Builder builder = BseSysMessage.newBuilder();
	builder.setMessage(message);
	builder.setSeconds(5000);
	builder.setAction(XinqiSysMessage.Action.NOOP);
	builder.setType(XinqiSysMessage.Type.NORMAL);
	BseSysMessage sysMessage = builder.build();
	
	XinqiMessage response = new XinqiMessage();
	response.payload = sysMessage;
	session.write(response);
	
	return result;
}
 
開發者ID:wangqi,項目名稱:gameserver,代碼行數:72,代碼來源:EmailManager.java

示例11: getPasswrod

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
/**
 * @Title: getpassword
 * @Description: TODO(會員忘記密碼,通過郵箱獲取密碼)
 * @param @param member
 * @param @param session
 * @param @return設定文件
 * @return Object 返回類型
 * @throws
 * 
 */
@RequestMapping(value = "/getPasswrod.htm", method = RequestMethod.GET)
public Object getPasswrod(@Valid
String useremal, HttpServletRequest request, HttpSession session) {
    JqReturnJson returnResult = new JqReturnJson();// 構建返回結果,默認結果為false
    Member member = new Member();
    if (useremal == null) {
        returnResult.setMsg("郵箱不能為空");
        // 郵箱不存在,就返回這個消息給前台
        session.setAttribute("emailStatus", "false");
        return "retrievePassword/retrievePasswordEmail";
    }
    member = memberService.retrieveEmail(useremal);
    if (member == null) {
        returnResult.setMsg("郵箱不存在");
        // 郵箱不存在,就返回這個消息給前台
        session.setAttribute("emailStatus", "false");
        return "retrievePassword/retrievePasswordEmail";
    }
    returnResult.setSuccess(true);
    ModelAndView mav = new ModelAndView("retrievePassword/sendMail");
    // 創建一個臨時ID
    String retrieveId = "" + Math.random() * Math.random();
    /**
     * 得到web係統url路徑的方法
     * */
    // 得到web的url路徑:http://localhost:8080/ssh1/
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    // 郵件發送成功後,用戶點在郵箱中點擊這個鏈接回到設置新密碼網站。
    String url = basePath + "mailBackPassword.htm?retrieveId=" + retrieveId;
    // 將驗證郵箱鏈接後麵的registerId存到session中
    session.setAttribute(retrieveId, retrieveId);
    session.setAttribute("userEmail", useremal);// 把用戶郵箱保存起來
    // 把用戶郵箱存起來
    // 設置session的有效時間,為10分鍾,10分鍾內沒有點擊鏈接的話,設置密碼將失敗
    session.setMaxInactiveInterval(600);
    // 基於org.apache.commons.mail,封裝好的mail,發郵件流程比較簡單,比原生態mail簡單。
    HtmlEmail email = new HtmlEmail();
    email.setHostName("smtp.qq.com");// QQ郵箱服務器
    // email.setHostName("smtp.163.com");// 163郵箱服務器
    // email.setHostName("smtp.gmail.com");// gmail郵箱服務器
    email.setSmtpPort(465);// 設置端口號
    email.setAuthenticator(new DefaultAuthenticator("[email protected]", "zx5304960"));// 用[email protected]這個郵箱發送驗證郵件的
    email.setTLS(true);// tls要設置為true,沒有設置會報錯。
    email.setSSL(true);// ssl要設置為true,沒有設置會報錯。
    try {
        email.setFrom("[email protected]", "冰川網貸管理員", "UTF-8");
        // email.setFrom("[email protected]", "[email protected]",
        // "UTF-8");
        // email.setFrom("[email protected]", "[email protected]", "UTF-8");
    } catch (EmailException e1) {
        e1.printStackTrace();
    }
    email.setCharset("UTF-8");// 沒有設置會亂碼。
    try {
        email.setSubject("冰川網貸密碼找回");// 設置郵件名稱
        email.setHtmlMsg("尊敬的會員:<font color='blue'>" + member.getMemberName() + "</font>,請點擊<a href='" + url + "'>" + url + "</a>完成新密碼設置!");// 設置郵件內容
        email.addTo(useremal);// 給會員發郵件
        email.send();// 郵件發送
    } catch (EmailException e) {
        throw new RuntimeException(e);
    }
    return mav;
}
 
開發者ID:GlacierSoft,項目名稱:netloan-project,代碼行數:75,代碼來源:RegisterController.java

示例12: sendVerifyEmail

import org.apache.commons.mail.HtmlEmail; //導入方法依賴的package包/類
/**
 * Send a verification email to the user's email account if exist.
 * 
 * @param user
 */
public void sendVerifyEmail(Account account, IoSession session) {
	if ( StringUtil.checkNotEmpty(account.getEmail()) ) {
		if ( StringUtil.checkValidEmail(account.getEmail()) ) {
			try {
				String emailSmtp = GameDataManager.getInstance().getGameDataAsString(GameDataKey.EMAIL_SMTP, "mail.xinqihd.com");
				HtmlEmail email = new HtmlEmail();
				email.setHostName(emailSmtp);
				email.setAuthenticator(new DefaultAuthenticator(EMAIL_FROM, "[email protected]"));
				email.setFrom(EMAIL_FROM);
				String subject = Text.text("email.subject");
				String http = StringUtil.concat(GlobalConfig.getInstance().getStringProperty("runtime.httpserverid"), 
						Constant.PATH_SEP, "verifyemail", Constant.QUESTION, account.get_id().toString());
				String content = Text.text("email.content", account.getUserName(), http);
				email.setSubject(subject);
				email.setHtmlMsg(content);
				email.setCharset("GBK");
				email.addTo(account.getEmail());
				email.send();

				SysMessageManager.getInstance().sendClientInfoRawMessage(session, Text.text("email.sent"), 
						Action.NOOP, Type.NORMAL);
			} catch (EmailException e) {
				logger.debug("Failed to send verify email to user {}'s address:{}", account.getUserName(), account.getEmail());
			}
		} else {
			//email not valid
			SysMessageManager.getInstance().sendClientInfoRawMessage(session, "email.invalid", Action.NOOP, Type.NORMAL);
		}
	} else {
		//no email at all
		SysMessageManager.getInstance().sendClientInfoRawMessage(session, "email.no", Action.NOOP, Type.NORMAL);
	}
}
 
開發者ID:wangqi,項目名稱:gameserver,代碼行數:39,代碼來源:EmailManager.java


注:本文中的org.apache.commons.mail.HtmlEmail.setAuthenticator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。