Java Code Examples for org.apache.commons.mail.HtmlEmail#setFrom()
The following examples show how to use
org.apache.commons.mail.HtmlEmail#setFrom() .
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 File: SendMailUtil.java From jeewx-boot with Apache License 2.0 | 6 votes |
/** * 发送普通邮件 * @param toMailAddr 收信人地址 * @param subject email主题 * @param message 发送email信息 */ public static boolean sendCommonMail(String toMailAddr, String subject, String message) { HtmlEmail hemail = new HtmlEmail(); try { SystemProperties systemProperties = ApplicationContextUtil.getBean(SystemProperties.class); hemail.setHostName(systemProperties.getSmtpHost()); hemail.setSmtpPort(getSmtpPort(systemProperties.getSender())); hemail.setCharset(charSet); hemail.addTo(toMailAddr); hemail.setFrom(systemProperties.getSender(), fromName); hemail.setAuthentication(systemProperties.getUser(), systemProperties.getPwd()); hemail.setSubject(subject); hemail.setMsg(message); hemail.send(); log.info("send email to "+toMailAddr+" OK!"); return true; } catch (Exception e) { e.printStackTrace(); log.info("send email to "+toMailAddr+" error!"+ e.toString()); return false; } }
Example 2
Source File: ReportMailer.java From AisAbnormal with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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 3
Source File: SendMailUtil.java From jeewx with Apache License 2.0 | 6 votes |
/** * 发送普通邮件 * @param toMailAddr 收信人地址 * @param subject email主题 * @param message 发送email信息 */ public static void sendCommonMail(String toMailAddr, String subject, String message) { HtmlEmail hemail = new HtmlEmail(); try { hemail.setHostName(getHost(from)); hemail.setSmtpPort(getSmtpPort(from)); hemail.setCharset(charSet); hemail.addTo(toMailAddr); hemail.setFrom(from, fromName); hemail.setAuthentication(username, password); hemail.setSubject(subject); hemail.setMsg(message); hemail.send(); org.jeecgframework.core.util.LogUtil.info("email send true!"); } catch (Exception e) { e.printStackTrace(); org.jeecgframework.core.util.LogUtil.info("email send error!"); } }
Example 4
Source File: SendMailUtil.java From jeecg with Apache License 2.0 | 6 votes |
/** * 发送普通邮件 * @param toMailAddr 收信人地址 * @param subject email主题 * @param message 发送email信息 */ public static void sendCommonMail(String toMailAddr, String subject, String message) { HtmlEmail hemail = new HtmlEmail(); try { hemail.setHostName(getHost(from)); hemail.setSmtpPort(getSmtpPort(from)); hemail.setCharset(charSet); hemail.addTo(toMailAddr); hemail.setFrom(from, fromName); hemail.setAuthentication(username, password); hemail.setSubject(subject); hemail.setMsg(message); hemail.send(); org.jeecgframework.core.util.LogUtil.info("email send true!"); } catch (Exception e) { e.printStackTrace(); org.jeecgframework.core.util.LogUtil.info("email send error!"); } }
Example 5
Source File: MailUtil.java From JARVIS with MIT License | 6 votes |
public void send(Mail mail) throws EmailException { // ����email HtmlEmail email = new HtmlEmail(); // ������SMTP���ͷ����������֣�163�����£�"smtp.163.com" email.setHostName(mail.getHost()); // �ַ����뼯������ email.setCharset(Mail.ENCODEING); // �ռ��˵����� email.addTo(mail.getReceiver()); // �����˵����� email.setFrom(mail.getSender(), mail.getName()); // �����Ҫ��֤��Ϣ�Ļ���������֤���û���-���롣�ֱ�Ϊ���������ʼ��������ϵ�ע�����ƺ����� email.setAuthentication(mail.getUsername(), mail.getPassword()); // Ҫ���͵��ʼ����� email.setSubject(mail.getSubject()); // Ҫ���͵���Ϣ������ʹ����HtmlEmail���������ʼ�������ʹ��HTML��ǩ email.setMsg(mail.getMessage()); //��Ӹ��� if(mail.getAttachment()!=null) email.attach(mail.getAttachment()); // ���� email.send(); System.out.println(mail.getSender() + " �����ʼ��� " + mail.getReceiver()); }
Example 6
Source File: EmailMessageSender.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 7
Source File: SendMailUtil.java From Shop-for-JavaWeb with MIT License | 6 votes |
/** * 发送普通邮件 * * @param toMailAddr * 收信人地址 * @param subject * email主题 * @param message * 发送email信息 */ public static void sendCommonMail(String toMailAddr, String subject, String message) { HtmlEmail hemail = new HtmlEmail(); try { hemail.setHostName(getHost(from)); hemail.setSmtpPort(getSmtpPort(from)); hemail.setCharset(charSet); hemail.addTo(toMailAddr); hemail.setFrom(from, fromName); hemail.setAuthentication(username, password); hemail.setSubject(subject); hemail.setMsg(message); hemail.send(); System.out.println("email send true!"); } catch (Exception e) { e.printStackTrace(); System.out.println("email send error!"); } }
Example 8
Source File: SendMailSsl.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
/** * 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; }
Example 9
Source File: EmailHelper.java From incubator-pinot with Apache License 2.0 | 5 votes |
/** 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 10
Source File: DetectionEmailAlerter.java From incubator-pinot with Apache License 2.0 | 5 votes |
private HtmlEmail prepareEmailContent(DetectionAlertConfigDTO subsConfig, Properties emailClientConfigs, List<AnomalyResult> anomalies, DetectionAlertFilterRecipients recipients) throws Exception { configureAdminRecipients(recipients); whitelistRecipients(recipients); blacklistRecipients(recipients); validateAlert(recipients, anomalies); BaseNotificationContent content = buildNotificationContent(emailClientConfigs); EmailEntity emailEntity = new EmailContentFormatter(emailClientConfigs, content, this.teConfig, subsConfig) .getEmailEntity(anomalies); if (Strings.isNullOrEmpty(this.subsConfig.getFrom())) { String fromAddress = MapUtils.getString(this.teConfig.getAlerterConfiguration().get(SMTP_CONFIG_KEY), PROP_FROM_ADDRESS); if (Strings.isNullOrEmpty(fromAddress)) { throw new IllegalArgumentException("Invalid sender's email"); } this.subsConfig.setFrom(fromAddress); } HtmlEmail email = emailEntity.getContent(); email.setSubject(emailEntity.getSubject()); email.setFrom(this.subsConfig.getFrom()); email.setTo(AlertUtils.toAddress(recipients.getTo())); if (!CollectionUtils.isEmpty(recipients.getCc())) { email.setCc(AlertUtils.toAddress(recipients.getCc())); } if (!CollectionUtils.isEmpty(recipients.getBcc())) { email.setBcc(AlertUtils.toAddress(recipients.getBcc())); } return getHtmlContent(emailEntity); }
Example 11
Source File: MimeMessageParserTest.java From commons-email with Apache License 2.0 | 5 votes |
@Test public void testParseCreatedHtmlEmailWithMixedContent() throws Exception { final Session session = Session.getDefaultInstance(new Properties()); final HtmlEmail email = new HtmlEmail(); email.setMailSession(session); email.setFrom("[email protected]"); email.setSubject("Test Subject"); email.addTo("[email protected]"); email.setTextMsg("My test message"); email.setHtmlMsg("<p>My HTML message</p>"); email.buildMimeMessage(); final MimeMessage msg = email.getMimeMessage(); final MimeMessageParser mimeMessageParser = new MimeMessageParser(msg); mimeMessageParser.parse(); assertEquals("Test Subject", mimeMessageParser.getSubject()); assertNotNull(mimeMessageParser.getMimeMessage()); assertTrue(mimeMessageParser.isMultipart()); assertTrue(mimeMessageParser.hasHtmlContent()); assertTrue(mimeMessageParser.hasPlainContent()); assertNotNull(mimeMessageParser.getPlainContent()); assertNotNull(mimeMessageParser.getHtmlContent()); assertTrue(mimeMessageParser.getTo().size() == 1); assertTrue(mimeMessageParser.getCc().size() == 0); assertTrue(mimeMessageParser.getBcc().size() == 0); assertEquals("[email protected]", mimeMessageParser.getFrom()); assertEquals("[email protected]", mimeMessageParser.getReplyTo()); assertFalse(mimeMessageParser.hasAttachments()); }
Example 12
Source File: MimeMessageParserTest.java From commons-email with Apache License 2.0 | 5 votes |
@Test public void testParseCreatedHtmlEmailWithNoContent() throws Exception { final Session session = Session.getDefaultInstance(new Properties()); final HtmlEmail email = new HtmlEmail(); email.setMailSession(session); email.setFrom("[email protected]"); email.setSubject("Test Subject"); email.addTo("[email protected]"); email.buildMimeMessage(); final MimeMessage msg = email.getMimeMessage(); final MimeMessageParser mimeMessageParser = new MimeMessageParser(msg); mimeMessageParser.parse(); assertEquals("Test Subject", mimeMessageParser.getSubject()); assertNotNull(mimeMessageParser.getMimeMessage()); assertTrue(mimeMessageParser.isMultipart()); assertFalse(mimeMessageParser.hasHtmlContent()); assertFalse(mimeMessageParser.hasPlainContent()); assertNull(mimeMessageParser.getPlainContent()); assertNull(mimeMessageParser.getHtmlContent()); assertTrue(mimeMessageParser.getTo().size() == 1); assertTrue(mimeMessageParser.getCc().size() == 0); assertTrue(mimeMessageParser.getBcc().size() == 0); assertEquals("[email protected]", mimeMessageParser.getFrom()); assertEquals("[email protected]", mimeMessageParser.getReplyTo()); assertFalse(mimeMessageParser.hasAttachments()); }
Example 13
Source File: MimeMessageParserTest.java From commons-email with Apache License 2.0 | 5 votes |
@Test public void testParseCreatedHtmlEmailWithTextContent() throws Exception { final Session session = Session.getDefaultInstance(new Properties()); final HtmlEmail email = new HtmlEmail(); email.setMailSession(session); email.setFrom("[email protected]"); email.setSubject("Test Subject"); email.addTo("[email protected]"); email.setTextMsg("My test message"); email.buildMimeMessage(); final MimeMessage msg = email.getMimeMessage(); final MimeMessageParser mimeMessageParser = new MimeMessageParser(msg); mimeMessageParser.parse(); assertEquals("Test Subject", mimeMessageParser.getSubject()); assertNotNull(mimeMessageParser.getMimeMessage()); assertTrue(mimeMessageParser.isMultipart()); assertFalse(mimeMessageParser.hasHtmlContent()); assertTrue(mimeMessageParser.hasPlainContent()); assertNotNull(mimeMessageParser.getPlainContent()); assertNull(mimeMessageParser.getHtmlContent()); assertTrue(mimeMessageParser.getTo().size() == 1); assertTrue(mimeMessageParser.getCc().size() == 0); assertTrue(mimeMessageParser.getBcc().size() == 0); assertEquals("[email protected]", mimeMessageParser.getFrom()); assertEquals("[email protected]", mimeMessageParser.getReplyTo()); assertFalse(mimeMessageParser.hasAttachments()); }
Example 14
Source File: MailUtil.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
/** * @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 15
Source File: MailUtil.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
/** * @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 16
Source File: EmailUtils.java From frpMgr with MIT License | 5 votes |
/** * 发送邮件 * @param toAddress 接收地址 * @param subject 标题 * @param content 内容 * @return */ public static boolean send(String fromAddress, String fromPassword, String fromHostName, String sslOnConnect, String sslSmtpPort, String toAddress, String subject, String content) { try { HtmlEmail htmlEmail = new HtmlEmail(); // 发送地址 htmlEmail.setFrom(fromAddress); // 密码校验 htmlEmail.setAuthentication(fromAddress, fromPassword); // 发送服务器协议 htmlEmail.setHostName(fromHostName); // SSL if ("true".equals(sslOnConnect)) { htmlEmail.setSSLOnConnect(true); htmlEmail.setSslSmtpPort(sslSmtpPort); } // 接收地址 htmlEmail.addTo(toAddress); // 标题 htmlEmail.setSubject(subject); // 内容 htmlEmail.setMsg(content); // 其他信息 htmlEmail.setCharset("utf-8"); // 发送 htmlEmail.send(); return true; } catch (Exception ex) { logger.error(ex.getMessage(), ex); } return false; }
Example 17
Source File: MailUtil.java From open-capacity-platform with Apache License 2.0 | 5 votes |
/** * * @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 18
Source File: RegistrationController.java From MaxKey with Apache License 2.0 | 4 votes |
@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 19
Source File: EmailManager.java From gameserver with Apache License 2.0 | 4 votes |
/** * 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, "xinqi@2012")); 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; }
Example 20
Source File: EmailHelper.java From dts-shop with GNU Lesser General Public License v3.0 | 4 votes |
/** * 发送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; } }