@Signature public String send(PEmailBackend backend) throws EmailException { backend._apply(htmlEmail); return htmlEmail.send(); } }
/** * @param subject 主题 * @param body 内容 * @param attachment 附件 * @param recipients 收件人 */ public static void sendHtml(String subject, String body, EmailAttachment attachment, String... recipients) { try { HtmlEmail htmlEmail = getHtmlEmail(subject, body, attachment, recipients); htmlEmail.send(); logger.info("send email to {}", Joiner.on(",").useForNull("null").join(recipients)); } catch (EmailException e) { throw new MailException("Unabled to send email", e); } }
HtmlEmail email = new HtmlEmail(); email.setHostName(mailserver); email.setAuthentication(username, password); email.setSmtpPort(port); email.setFrom(fromEmail); email.addTo(to); email.setSubject(subject); email.setTextMsg(textBody); email.setHtmlMsg(htmlBody); email.setDebug(true); email.send();
@Override public void send() { try { wrappedEmail.send(); } catch (EmailException e) { throw new IllegalStateException("Could not send the email.", e); } } }
public static void sendSimpleEmail(String emails, String subject, String message, boolean initializeEmail) throws EmailException { if (initializeEmail) { initializeEmail(AppProperties.getInstance().getEmailSettings()); } email.setCharset("UTF-8"); email.setSubject(subject); email.setHtmlMsg(message); email.addTo(emails.split(",")); String sendReturn = email.send(); _logger.debug("Send Status:[{}]", sendReturn); _logger.debug("EmailSettings successfully sent to [{}], Message:[{}]", emails, message); }
public static void sendSimpleEmail(String emails, String subject, String message, boolean initializeEmail) throws EmailException { if (initializeEmail) { initializeEmail(AppProperties.getInstance().getEmailSettings()); } email.setCharset("UTF-8"); email.setSubject(subject); email.setHtmlMsg(message); email.addTo(emails.split(",")); String sendReturn = email.send(); _logger.debug("Send Status:[{}]", sendReturn); _logger.debug("EmailSettings successfully sent to [{}], Message:[{}]", emails, message); }
/** * Sends a HTML email using the SMTP configuration in application.conf * * For more information @see <a href="https://commons.apache.org/proper/commons-email/userguide.html">https://commons.apache.org/proper/commons-email/userguide.html</a> * * @param htmlEmail The HTML email to send */ public void send(HtmlEmail htmlEmail) { htmlEmail.setHostName(this.host); htmlEmail.setSmtpPort(this.port); htmlEmail.setAuthenticator(this.defaultAuthenticator); htmlEmail.setSSLOnConnect(this.ssl); try { htmlEmail.send(); } catch (EmailException e) { LOG.error("Failed to send HtmlEmail", e); } } }
private void createAndSendAlertEmail(String body) { try { log.info(String.format("Sending alert email to [%s]: %s", config.getRecipients(), body)); HtmlEmail email = new HtmlEmail(); email.setTextMsg(body); email.setFrom("esper-is-awesome@example.com"); email.setTo(Arrays.asList(new InternetAddress(config.getRecipients()))); email.setHostName(config.getHost()); email.setSmtpPort(config.getPort()); email.send(); } catch (Exception ex) { log.warn("Could not create or send email", ex); } } }
/** * 发送工单反馈通知邮件 * * @param userDO * @param dailyVO * @return */ public boolean doSendInitFeedbackTodo(UserDO userDO, TodoDailyVO dailyVO, UserDO sponsorUser) { logger.info("send init feedback todo email to:" + userDO.getUsername() + " for id:" + dailyVO.getId()); try { HtmlEmail email = buildHtmlEmail(userDO.getMail(), userDO.getDisplayName()); // set the html message email.setHtmlMsg(TplUtils.doInitFeedbackNotify(sponsorUser, dailyVO, userDO.getDisplayName())); // send the email email.send(); return true; } catch (Exception e) { logger.error(e.getMessage(), e); return false; } }
/** * 发送处理完成通知邮件 * * @param userDO * @param dailyVO * @return */ public boolean doFinishTodo(UserDO userDO, TodoDailyVO dailyVO, UserDO sponsorUser) { logger.info("send finish todo email to:" + userDO.getUsername() + " for id:" + dailyVO.getId()); try { HtmlEmail email = buildHtmlEmail(userDO.getMail(), userDO.getDisplayName()); // set the html message email.setHtmlMsg(TplUtils.doFinishNotify(sponsorUser, dailyVO, userDO.getDisplayName())); // send the email email.send(); return true; } catch (Exception e) { logger.error(e.getMessage(), e); return false; } }
private void sendHtmlMail(String fromEmail, String fromPasswd,String fromName, String host,List<String> toEmailList,MailMsg mailMsg){ HtmlEmail email = new HtmlEmail(); try { initEmail(email, fromEmail, fromPasswd, fromName,host, toEmailList, mailMsg); email.setHtmlMsg(mailMsg.getContent()); email.send(); } catch (EmailException e) { e.printStackTrace(); } }
public boolean doSendCompleteTodo(TodoDetailVO todoDetailVO) { logger.info("send complete todo email to:" + todoDetailVO.getInitiatorUsername() + " for id:" + todoDetailVO.getId()); try { HtmlEmail email = buildHtmlEmail(todoDetailVO.getInitiatorUserDO().getMail(), todoDetailVO.getInitiatorUserDO().getDisplayName()); // set the html message email.setHtmlMsg(TplUtils.doCompleteTodoNotify(todoDetailVO, todoDetailVO.getInitiatorUserDO().getDisplayName())); // send the email email.send(); return true; } catch (Exception e) { logger.error(e.getMessage(), e); return false; } }
public void sendHtmlEmails(Map toEmails, String subject, String htmlMsg) throws Exception { try { HtmlEmail email = new HtmlEmail(); this.setEmail(email, toEmails, subject, "HtmlEmail"); email.setHtmlMsg(htmlMsg); email .setTextMsg("Your email client does not support HTML messages"); email.send(); } catch (EmailException e) { // TODO Auto-generated catch block e.printStackTrace(); throw e; } }
public void sendHtmlEmail(String toEmail, String toName, String subject, String htmlMsg) throws Exception { try { HtmlEmail email = new HtmlEmail(); this.setEmail(email, toEmail, toName, subject, "HtmlEmail", null, null); email.setHtmlMsg(htmlMsg); email .setTextMsg("Your email client does not support HTML messages"); email.send(); } catch (EmailException e) { // TODO Auto-generated catch block e.printStackTrace(); throw e; } }
HtmlEmail email = new HtmlEmail(); email.setSubject("<your subject>"); email.setHtmlMsg("<your html message body>"); email.setHostName("<host>"); email.setFrom("<from_address>"); email.addTo("<recipient_address>"); email.send();
public static void main(String[] args) throws EmailException, MalformedURLException { // 创建 Email Message HtmlEmail email = new HtmlEmail(); email.setHostName("mail.myserver.com"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("Test email with inline image"); // 嵌入图片 URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif"); String cid = email.embed(url, "Apache logo"); // 发送 HTML 内容 email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>"); // 设置替代消息 email.setTextMsg("Your email client does not support HTML messages"); // 发送 email.send(); } }
@Override public void send(final SessionInfo sessionInfo, final String subject, final String message, final String fallbackMessage) throws Exception { final HtmlEmail email = createNewEmail(sessionInfo); email.setSubject(subject); email.setHtmlMsg(message); email.setTextMsg(fallbackMessage); LOGGER.debug("Will send '{}' from {} to {} through {}:{} as {}.", email.getSubject(), email.getFromAddress(), email.getToAddresses(), email.getHostName(), email.getSmtpPort(), getSmtpUsername()); email.send(); } }
@Override public void send(final SessionInfo sessionInfo, final String subject, final String message, final String fallbackMessage) throws Exception { final HtmlEmail email = createNewEmail(sessionInfo); email.setSubject(subject); email.setHtmlMsg(message); email.setTextMsg(fallbackMessage); LOGGER.debug("Will send '{}' from {} to {} through {}:{} as {}.", email.getSubject(), email.getFromAddress(), email.getToAddresses(), email.getHostName(), email.getSmtpPort(), getSmtpUsername()); email.send(); } }
public boolean send(String to, String subject, String templateFile, Map<String, Object> root) { try { HtmlEmail email = ioc.get(HtmlEmail.class); email.setCharset("UTF-8"); email.setSubject(subject); email.setHtmlMsg(processTemplateIntoString(templateFile, root)); email.addTo(to); String res = email.send(); if (log.isDebugEnabled()) { log.debug(res); } return true; } catch (Exception e) { log.error("send email fail", e); return false; } }
HtmlEmail htmlEmail = new HtmlEmail(); htmlEmail.setHostName("smtp.gmail.com"); htmlEmail.setSmtpPort(587); htmlEmail.setDebug(true); htmlEmail.setAuthenticator(new DefaultAuthenticator("userId", "password")); htmlEmail.setTLS(true); htmlEmail.addTo("recipient@gmail.com", "recipient"); htmlEmail.setFrom("sender@gmail.com", "sender"); htmlEmail.setSubject("Send HTML email with body content from URI"); htmlEmail.setHtmlMsg(responseBody); htmlEmail.send();