org.apache.commons.mail.DefaultAuthenticator Java Examples

The following examples show how to use org.apache.commons.mail.DefaultAuthenticator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: judgels   Author: ia-toki   File: Mailer.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void send(String recipient, String subject, String body) {
    new Thread(() -> {
        try {
            HtmlEmail email = new HtmlEmail();
            email.setHostName(config.getHost());
            email.setSmtpPort(config.getPort());
            email.setAuthenticator(new DefaultAuthenticator(config.getUsername(), config.getPassword()));
            email.setSSLOnConnect(config.getUseSsl());
            email.setFrom(config.getSender());
            email.setSubject(subject);
            email.setHtmlMsg(body);
            email.addTo(recipient);
            email.send();
        } catch (EmailException e) {
            throw new RuntimeException(e);
        }
    }).start();
}
 
Example #2
Source Project: shepher   Author: XiaoMi   File: GeneralMailSender.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #3
Source Project: bobcat   Author: Cognifide   File: EmailSender.java    License: Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #4
Source Project: MaxKey   Author: shimingxy   File: MailTest.java    License: Apache License 2.0 6 votes vote down vote up
public void test() throws Exception {
String username="[email protected]";
String password="3&8Ujbnm5hkjhFD";
String smtpHost="smtp.exmail.qq.com";
int port=465;
boolean ssl=true;
String senderMail="[email protected]";

Email email = new SimpleEmail();
email.setHostName(smtpHost);
email.setSmtpPort(port);
email.setAuthenticator(new DefaultAuthenticator(username, password));
email.setSSLOnConnect(ssl);
email.setFrom(senderMail);
email.setSubject("One Time PassWord");
email.setMsg("You Token is "+111+" , it validity in "+5 +" minutes");
email.addTo("[email protected]");
email.send();
}
 
Example #5
Source Project: dhis2-core   Author: dhis2   File: EmailMessageSender.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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, getEmailName() );
    email.setSmtpPort( port );
    email.setStartTLSEnabled( tls );

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

    return email;
}
 
Example #6
Source Project: gameserver   Author: wangqi   File: EmailManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example #7
Source Project: AisAbnormal   Author: dma-ais   File: ReportMailer.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #8
Source Project: open-capacity-platform   Author: open-capacity-platform   File: MailUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param toAddress		收件人邮箱
 * @param mailSubject	邮件主题
 * @param mailBody		邮件正文
 * @return
 */
public static boolean sendMail(String toAddress, String mailSubject, String mailBody){

	try {
		// Create the email message
		HtmlEmail email = new HtmlEmail();

		//email.setDebug(true);		// 将会打印一些log
		//email.setTLS(true);		// 是否TLS校验,,某些邮箱需要TLS安全校验,同理有SSL校验
		//email.setSSL(true);

		email.setHostName(PropertiesUtil.getString("xxl.job.mail.host"));

		if ("true".equals(PropertiesUtil.getString("xxl.job.mail.ssl"))) {
			email.setSslSmtpPort(PropertiesUtil.getString("xxl.job.mail.port"));
			email.setSSLOnConnect(true);
		} else {
			email.setSmtpPort(Integer.valueOf(PropertiesUtil.getString("xxl.job.mail.port")));
		}

		email.setAuthenticator(new DefaultAuthenticator(PropertiesUtil.getString("xxl.job.mail.username"), 
				PropertiesUtil.getString("xxl.job.mail.password")));
		email.setCharset(Charset.defaultCharset().name());

		email.setFrom(PropertiesUtil.getString("xxl.job.mail.username"), PropertiesUtil.getString("xxl.job.mail.sendNick"));
		email.addTo(toAddress);
		email.setSubject(mailSubject);
		email.setMsg(mailBody);

		//email.attach(attachment);	// add the attachment

		email.send();				// send the email
		return true;
	} catch (EmailException e) {
		logger.error(e.getMessage(), e);

	}
	return false;
}
 
Example #9
Source Project: zuihou-admin-boot   Author: zuihou   File: MailUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param toAddress   收件人邮箱
 * @param mailSubject 邮件主题
 * @param mailBody    邮件正文
 * @return
 */
public static boolean sendMail(String toAddress, String mailSubject, String mailBody) {

    try {
        // Create the email message
        HtmlEmail email = new HtmlEmail();

        //email.setDebug(true);		// 将会打印一些log
        //email.setTLS(true);		// 是否TLS校验,,某些邮箱需要TLS安全校验,同理有SSL校验
        //email.setSSL(true);

        email.setHostName(XxlJobAdminConfig.getAdminConfig().getMailHost());

        if (XxlJobAdminConfig.getAdminConfig().isMailSSL()) {
            email.setSslSmtpPort(XxlJobAdminConfig.getAdminConfig().getMailPort());
            email.setSSLOnConnect(true);
        } else {
            email.setSmtpPort(Integer.valueOf(XxlJobAdminConfig.getAdminConfig().getMailPort()));
        }

        email.setAuthenticator(new DefaultAuthenticator(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailPassword()));
        email.setCharset("UTF-8");

        email.setFrom(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailSendNick());
        email.addTo(toAddress);
        email.setSubject(mailSubject);
        email.setMsg(mailBody);

        //email.attach(attachment);	// add the attachment

        email.send();                // send the email
        return true;
    } catch (EmailException e) {
        logger.error(e.getMessage(), e);

    }
    return false;
}
 
Example #10
Source Project: zuihou-admin-cloud   Author: zuihou   File: MailUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param toAddress   收件人邮箱
 * @param mailSubject 邮件主题
 * @param mailBody    邮件正文
 * @return
 */
public static boolean sendMail(String toAddress, String mailSubject, String mailBody) {

    try {
        // Create the email message
        HtmlEmail email = new HtmlEmail();

        //email.setDebug(true);		// 将会打印一些log
        //email.setTLS(true);		// 是否TLS校验,,某些邮箱需要TLS安全校验,同理有SSL校验
        //email.setSSL(true);

        email.setHostName(XxlJobAdminConfig.getAdminConfig().getMailHost());

        if (XxlJobAdminConfig.getAdminConfig().isMailSSL()) {
            email.setSslSmtpPort(XxlJobAdminConfig.getAdminConfig().getMailPort());
            email.setSSLOnConnect(true);
        } else {
            email.setSmtpPort(Integer.valueOf(XxlJobAdminConfig.getAdminConfig().getMailPort()));
        }

        email.setAuthenticator(new DefaultAuthenticator(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailPassword()));
        email.setCharset("UTF-8");

        email.setFrom(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailSendNick());
        email.addTo(toAddress);
        email.setSubject(mailSubject);
        email.setMsg(mailBody);

        //email.attach(attachment);	// add the attachment

        email.send();                // send the email
        return true;
    } catch (EmailException e) {
        logger.error(e.getMessage(), e);

    }
    return false;
}
 
Example #11
Source Project: Notebook   Author: coding-dream   File: EmailManager.java    License: Apache License 2.0 5 votes vote down vote up
private ImageHtmlEmail createImageEmail(EmailFrom emailFrom, String _url, String html) throws Exception {
       ImageHtmlEmail email = new ImageHtmlEmail();
       email.setCharset("UTF-8");
	URL url = new URL(_url);
	email.setDataSourceResolver(new DataSourceUrlResolver(url));
	email.setHostName(emailFrom.getHostName());
    email.setSmtpPort(emailFrom.getSmtpPort());
    email.setAuthenticator(new DefaultAuthenticator(emailFrom.getUser(), emailFrom.getPwd()));
    email.setSSLOnConnect(true);
       email.setFrom(emailFrom.getFromAddr(), emailFrom.getFromNick());
       email.setSubject(emailFrom.getSubject());
       email.setTextMsg(emailFrom.getText());
       email.setHtmlMsg(html);
       return email;
}
 
Example #12
Source Project: MaxKey   Author: shimingxy   File: MailOtpAuthn.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean produce(UserInfo userInfo) {
    try {
        String token = this.genToken(userInfo);
        Email email = new SimpleEmail();
        email.setHostName(emailConfig.getSmtpHost());
        email.setSmtpPort(emailConfig.getPort());
        email.setSSLOnConnect(emailConfig.isSsl());
        email.setAuthenticator(
                new DefaultAuthenticator(emailConfig.getUsername(), emailConfig.getPassword()));
        
        email.setFrom(emailConfig.getSender());
        email.setSubject(subject);
        email.setMsg(
                MessageFormat.format(
                        messageTemplate,userInfo.getUsername(),token,(interval / 60)));
        
        email.addTo(userInfo.getEmail());
        email.send();
        _logger.debug(
                "token " + token + " send to user " + userInfo.getUsername() 
                + ", email " + userInfo.getEmail());
        //成功返回
        this.optTokenStore.store(
                userInfo, 
                token, 
                userInfo.getMobile(), 
                OptTypes.EMAIL);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
Example #13
Source Project: gameserver   Author: wangqi   File: EmailManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example #14
Source Project: incubator-pinot   Author: apache   File: DetectionEmailAlerter.java    License: Apache License 2.0 5 votes vote down vote up
/** Sends email according to the provided config. */
private void sendEmail(HtmlEmail email) throws EmailException {
  SmtpConfiguration config = this.smtpConfig;
  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.setSslSmtpPort(Integer.toString(config.getSmtpPort()));
  }
  email.send();

  int recipientCount = email.getToAddresses().size() + email.getCcAddresses().size() + email.getBccAddresses().size();
  LOG.info("Email sent with subject '{}' to {} recipients", email.getSubject(), recipientCount);
}
 
Example #15
Source Project: incubator-pinot   Author: apache   File: EmailHelper.java    License: Apache License 2.0 5 votes vote down vote up
/** Sends email according to the provided config. */
private static void sendEmail(SmtpConfiguration config, HtmlEmail email, String subject,
    String fromAddress, DetectionAlertFilterRecipients recipients) throws EmailException {
  if (config != null) {
    email.setSubject(subject);
    LOG.info("Sending email to {}", recipients.toString());
    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);
    email.setTo(AlertUtils.toAddress(recipients.getTo()));
    if (CollectionUtils.isNotEmpty(recipients.getCc())) {
      email.setCc(AlertUtils.toAddress(recipients.getCc()));
    }
    if (CollectionUtils.isNotEmpty(recipients.getBcc())) {
      email.setBcc(AlertUtils.toAddress(recipients.getBcc()));
    }
    email.send();
    LOG.info("Email sent with subject [{}] to address [{}]!", subject, recipients.toString());
  } else {
    LOG.error("No email config provided for email with subject [{}]!", subject);
  }
}
 
Example #16
Source Project: dts-shop   Author: qiguliuxing   File: EmailHelper.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 发送HTML格式的邮件
 *
 * @param host
 *            Email服务器主机
 * @param port
 *            Email服务器端口
 * @param userName
 *            登录账号
 * @param password
 *            登录密码
 * @param sslEnabled
 *            是否启用SSL
 * @param toAddress
 *            邮件接受者地址
 * @param fromAddress
 *            邮件发送者地址
 * @param fromName
 *            邮件发送者名称
 * @param subject
 *            邮件主题
 * @param htmlContent
 *            邮件内容,HTML格式
 * @return 邮件发送的MessageId,若为<code>null</code>,则发送失败
 */
public static String sendHtml(String host, int port, String userName, String password, boolean sslEnabled,
		String fromAddress, String fromName, String[] toAddress, String subject, String htmlContent) {
	HtmlEmail email = new HtmlEmail();
	email.setHostName(host);
	email.setSmtpPort(port);
	email.setAuthenticator(new DefaultAuthenticator(userName, password));
	email.setCharset("UTF-8");
	if (sslEnabled) {
		email.setSslSmtpPort(String.valueOf(port));
		email.setSSLOnConnect(true);
	}
	try {
		email.setFrom(fromAddress, fromName);
		email.addTo(toAddress);
		email.setSubject(subject);
		email.setHtmlMsg(htmlContent);
		return email.send();
	} catch (EmailException e) {
		return null;
	}
}
 
Example #17
Source Project: MaxKey   Author: shimingxy   File: RegistrationController.java    License: Apache License 2.0 4 votes vote down vote up
@RequestMapping(value={"/register"})
public ModelAndView reg(@ModelAttribute("registration") Registration registration) {
	_logger.debug("Registration  /registration/register.");
	_logger.debug(""+registration);
	ModelAndView modelAndView= new ModelAndView("registration/registered");
	
	UserInfo userInfo =registrationService.queryUserInfoByEmail(registration.getWorkEmail());
	
	if(userInfo!=null){
		modelAndView.addObject("registered", 1);
		return modelAndView;
	}
	
	registration.setId(registration.generateId());
	registrationService.insert(registration);
	HtmlEmail email = new HtmlEmail();
	  
	  try {
		email.setHostName(applicationConfig.getEmailConfig().getSmtpHost());
		email.setSmtpPort(applicationConfig.getEmailConfig().getPort());
		email.setAuthenticator(new DefaultAuthenticator(applicationConfig.getEmailConfig().getUsername(), applicationConfig.getEmailConfig().getPassword()));
		
		email.addTo(registration.getWorkEmail(), registration.getLastName()+registration.getFirstName());
		email.setFrom(applicationConfig.getEmailConfig().getSender(), "ConnSec");
		email.setSubject("ConnSec Cloud Identity & Access Registration activate Email .");
		  
		String activateUrl=WebContext.getHttpContextPath()+"/registration/forward/activate/"+registration.getId();
		
		
		// set the html message
		String emailText="<html>";
		 			emailText+="<a href='"+activateUrl+"'>activate</a><br>";
		 			emailText+=" or copy "+activateUrl+" to brower.";
		 	   emailText+="</html>";
		email.setHtmlMsg(emailText);
		
		// set the alternative message
		email.setTextMsg("Your email client does not support HTML messages");
		
		// send the email
		email.send();
	} catch (EmailException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	  modelAndView.addObject("registered", 0); 
	return  modelAndView;
}
 
Example #18
Source Project: graylog-plugin-aggregates   Author: cvtienhoven   File: ReportSender.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
   * 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();
      
  }
 
Example #19
Source Project: gameserver   Author: wangqi   File: EmailManager.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}