Examples of HtmlEmail


Examples of org.apache.commons.mail.HtmlEmail

   */
  public static void sendFtlMail(String toMailAddr, String subject,
      String templatePath, Map<String, Object> map){
    Template template = null;
    Configuration freeMarkerConfig = null;
    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);
        freeMarkerConfig = new Configuration();
        freeMarkerConfig.setDirectoryForTemplateLoading(new File(getFilePath()));
        // 获取模板
      template = freeMarkerConfig.getTemplate(getFileName(templatePath),new Locale("Zh_cn"), "UTF-8");
      // 模板内容转换为string
      String htmlText = FreeMarkerTemplateUtils.processTemplateIntoString(template, map);
      org.jeecgframework.core.util.LogUtil.info(htmlText);
        hemail.setMsg(htmlText);
        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!");
      }
View Full Code Here

Examples of org.apache.commons.mail.HtmlEmail

   * @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!");
        }
View Full Code Here

Examples of org.apache.commons.mail.HtmlEmail

        notifiers.Welcome.welcome3();
        renderText("OK4");
    }

    public static void mail5() throws EmailException {
        HtmlEmail email = new HtmlEmail();
        email.setHtmlMsg("<html><body><h1>A Title</h1></body></html>");
        email.setTextMsg("alternative message");
        EmailAttachment attachment = new EmailAttachment();
        attachment.setDescription("An image");
        attachment.setDisposition(EmailAttachment.ATTACHMENT);
        attachment.setPath(Play.applicationPath.getPath() + java.io.File.separator + "test" + java.io.File.separator + "fond2.png");
        EmailAttachment attachment2 = new EmailAttachment();
        attachment2.setName("fond3.jpg");
        attachment2.setPath(Play.applicationPath.getPath() + java.io.File.separator + "test" + java.io.File.separator + "fond3.jpg");
        email.attach(attachment);
        email.attach(attachment2);
        email.setFrom("test@localhost");
        email.addTo("test@localhost");
        email.setSubject("test attachments");
        Mail.send(email);
        renderText("OK5");
    }
View Full Code Here

Examples of org.apache.commons.mail.HtmlEmail

   * @throws EmailException
   * @throws MalformedURLException
   */
  public static void sendHtmlMail(MailSenderInfo mailInfo)
      throws EmailException, MalformedURLException {
    HtmlEmail email = new HtmlEmail();
    System.out.println("----------------------email");
    email.setHostName(mailInfo.getHostName()); // 设定smtp服务器
    email.setSSL(mailInfo.getIsSSL()); // 设定是否使用SSL
    email.setSslSmtpPort(mailInfo.getSslSmtpPort()); // 设定SSL端口
    email.setAuthentication(mailInfo.getUserName(), mailInfo.getPassword()); // 设定smtp服务器的认证资料信息
    email.setDebug(mailInfo.getIsDebug()); // 是否用debug模式
    email.addTo(mailInfo.getToAddress(), mailInfo.getToName()); // 设定收件人
    email.setFrom(mailInfo.getFromAddress(), mailInfo.getFromName());
    email.setSubject(mailInfo.getSubject());
    // embed the image and get the content id
    File file = new File(mailInfo.getFilePath());
    String cid = email.embed(file);
    // set the html message
    email.setHtmlMsg("<html>" + mailInfo.getHtmlMsg() + "<img src=\"cid:"
        + cid + "\"></html>");

    // set the alternative message
    email.setTextMsg(mailInfo.getAltermessage());
    // send the email

    email.send();
  }
View Full Code Here

Examples of org.apache.commons.mail.HtmlEmail

      //Save on DB
      ResetPwdDao.getInstance().create(new Date(), sBase64Random, user);

      //Send mail
      HtmlEmail email = null;

      URL resetUrl = new URL(Application.NETWORK_HTTP_SSL.getValueAsBoolean()? "https" : "http", siteUrl, sitePort, "/user/password/reset/"+sBase64Random);

      //HTML Email Text
      ST htmlMailTemplate = new ST(htmlEmail, '$', '$');
      htmlMailTemplate.add("link", resetUrl);
      htmlMailTemplate.add("user_name", username);

      //Plain text Email Text
      ST textMailTemplate = new ST(textEmail, '$', '$');
      textMailTemplate.add("link", resetUrl);
      textMailTemplate.add("user_name", username);

      email = new HtmlEmail();

      email.setHtmlMsg(htmlMailTemplate.render());
      email.setTextMsg(textMailTemplate.render());

      //Email Configuration
      email.setSSL(useSSL);
      email.setSSLOnConnect(useSSL);
      email.setTLS(useTLS);
      email.setStartTLSEnabled(useTLS);
      email.setStartTLSRequired(useTLS);
      email.setSSLCheckServerIdentity(false);
      email.setSslSmtpPort(String.valueOf(smtpPort));  
      email.setHostName(smtpHost);
      email.setSmtpPort(smtpPort);
      email.setCharset("utf-8");

      if (PasswordRecovery.NETWORK_SMTP_AUTHENTICATION.getValueAsBoolean()) {
        email.setAuthenticator(new  DefaultAuthenticator(username_smtp, password_smtp));
      }
      email.setFrom(emailFrom);     
      email.addTo(userEmail);

      email.setSubject(emailSubject);
      if (Logger.isDebugEnabled()) {
        StringBuilder logEmail = new StringBuilder()
            .append("HostName: ").append(email.getHostName()).append("\n")
            .append("SmtpPort: ").append(email.getSmtpPort()).append("\n")
            .append("SslSmtpPort: ").append(email.getSslSmtpPort()).append("\n")
           
            .append("SSL: ").append(email.isSSL()).append("\n")
            .append("TLS: ").append(email.isTLS()).append("\n")           
            .append("SSLCheckServerIdentity: ").append(email.isSSLCheckServerIdentity()).append("\n")
            .append("SSLOnConnect: ").append(email.isSSLOnConnect()).append("\n")
            .append("StartTLSEnabled: ").append(email.isStartTLSEnabled()).append("\n")
            .append("StartTLSRequired: ").append(email.isStartTLSRequired()).append("\n")
           
            .append("SubType: ").append(email.getSubType()).append("\n")
            .append("SocketConnectionTimeout: ").append(email.getSocketConnectionTimeout()).append("\n")
            .append("SocketTimeout: ").append(email.getSocketTimeout()).append("\n")
           
            .append("FromAddress: ").append(email.getFromAddress()).append("\n")
            .append("ReplyTo: ").append(email.getReplyToAddresses()).append("\n")
            .append("BCC: ").append(email.getBccAddresses()).append("\n")
            .append("CC: ").append(email.getCcAddresses()).append("\n")
           
            .append("Subject: ").append(email.getSubject()).append("\n")

            //the following line throws a NPE in debug mode
            //.append("Message: ").append(email.getMimeMessage().getContent()).append("\n")

           
            .append("SentDate: ").append(email.getSentDate()).append("\n");
        Logger.debug("Password Recovery is ready to send: \n" + logEmail.toString());
      }
      email.send();

    catch (EmailException authEx){
      Logger.error("ERROR SENDING MAIL:" + ExceptionUtils.getStackTrace(authEx));
      throw new PasswordRecoveryException (errorString + " Could not reach the mail server. Please contact the server administrator");
    catch (Exception e) {
View Full Code Here

Examples of org.apache.commons.mail.HtmlEmail

        notifiers.Welcome.welcome3();
        renderText("OK4");
    }

    public static void mail5() throws EmailException {
        HtmlEmail email = new HtmlEmail();
        email.setHtmlMsg("<html><body><h1>A Title</h1></body></html>");
        email.setTextMsg("alternative message");
        EmailAttachment attachment = new EmailAttachment();
        attachment.setDescription("An image");
        attachment.setDisposition(EmailAttachment.ATTACHMENT);
        attachment.setPath(Play.applicationPath.getPath() + java.io.File.separator + "test" + java.io.File.separator + "fond2.png");
        EmailAttachment attachment2 = new EmailAttachment();
        attachment2.setName("fond3.jpg");
        attachment2.setPath(Play.applicationPath.getPath() + java.io.File.separator + "test" + java.io.File.separator + "fond3.jpg");
        email.attach(attachment);
        email.attach(attachment2);
        email.setFrom("test@localhost");
        email.addTo("test@localhost");
        email.setSubject("test attachments");
        Mail.send(email);
        renderText("OK5");
    }
View Full Code Here

Examples of org.apache.commons.mail.HtmlEmail

                                       
                                        Collection<String> addresses = AppUtil.getEmailList(null, username, null, null);
                                       
                                        if (addresses != null && addresses.size() > 0) {
                                            // create the email message
                                            final HtmlEmail email = new HtmlEmail();
                                            email.setHostName(smtpHost);
                                            if (smtpPort != null && smtpPort.length() != 0) {
                                                email.setSmtpPort(Integer.parseInt(smtpPort));
                                            }
                                            if (smtpUsername != null && !smtpUsername.isEmpty()) {
                                                String decryptedSmtpPassword = smtpPassword;
                                                if (decryptedSmtpPassword != null) {
                                                    decryptedSmtpPassword = SecurityUtil.decrypt(decryptedSmtpPassword);
                                                }
                                                email.setAuthentication(smtpUsername, decryptedSmtpPassword);
                                            }
                                            if(security!= null){
                                                if(security.equalsIgnoreCase("SSL") ){
                                                    email.setSSL(true);
                                                }else if(security.equalsIgnoreCase("TLS")){
                                                    email.setTLS(true);
                                                }
                                            }
                                            if (cc != null && cc.length() != 0) {
                                                Collection<String> ccs = AppUtil.getEmailList(null, cc, wfAssignment, appDef);
                                                for (String address : ccs) {
                                                    email.addCc(address);
                                                }
                                            }

                                            String emailToOutput = "";
                                            for (String address : addresses) {
                                                email.addTo(address);
                                                emailToOutput += address + ", ";
                                            }
                                            email.setFrom(from);

                                            if (subject != null && subject.length() != 0) {
                                                email.setSubject(WorkflowUtil.processVariable(subject, null, wfAssignment));
                                            }
                                            if (emailMessage != null && emailMessage.length() != 0) {
                                                String link = "";

                                                if (url != null && !url.isEmpty()) {
                                                    link += url;
                                                    if ("append".equals(passoverMethod)) {
                                                        if (!url.endsWith("/")) {
                                                            link += "/";
                                                        }
                                                        link += activityInstanceId;
                                                    } else if ("param".equals(passoverMethod)) {
                                                        if (url.contains("?")) {
                                                            link += "&";
                                                        } else {
                                                            link += "?";
                                                        }
                                                        link += parameterName + "=" + activityInstanceId;
                                                    }
                                                } else {
                                                    String urlMapping = "";

                                                    if (base.endsWith("/")) {
                                                        urlMapping = "web/client/app/assignment/";
                                                    } else {
                                                        urlMapping = "/web/client/app/assignment/";
                                                    }

                                                    link = base + urlMapping + activityInstanceId;
                                                }
                                               
                                                String msg;
                                                if("true".equalsIgnoreCase(isHtml)){
                                                    if(urlName != null && urlName.length() != 0){
                                                        link = "<a href=\"" + link + "\">" + urlName + "</a>";
                                                    }else{
                                                        link = "<a href=\"" + link + "\">" + link + "</a>";
                                                    }
                                                    msg = AppUtil.processHashVariable(emailMessage + "<br/><br/><br/>" + link, wfAssignment, null, replace);
                                                    msg = msg.replaceAll("\\n", "<br/>");
                                                    email.setHtmlMsg(msg);
                                                }else{
                                                    msg = AppUtil.processHashVariable(emailMessage + "\n\n\n" + link, wfAssignment, null, replace);
                                                    email.setMsg(msg);
                                                }
                                            }
                                            email.setCharset("UTF-8");
                                           
                                            try {
                                                LogUtil.info(UserNotificationAuditTrail.class.getName(), "Sending email from=" + email.getFromAddress().toString() + " to=" + emailToOutput + ", subject=Workflow - Pending Task Notification");
                                                email.send();
                                                LogUtil.info(UserNotificationAuditTrail.class.getName(), "Sending email completed for subject=" + email.getSubject());
                                            } catch (EmailException ex) {
                                                LogUtil.error(UserNotificationAuditTrail.class.getName(), ex, "Error sending email");
                                            }
                                        }
                                    }
View Full Code Here

Examples of org.apache.commons.mail.HtmlEmail

            smtpUsername = AppUtil.processHashVariable(smtpUsername, wfAssignment, null, null);
            smtpPassword = AppUtil.processHashVariable(smtpPassword, wfAssignment, null, null);
            security = AppUtil.processHashVariable(security, wfAssignment, null, null);

            // create the email message
            final HtmlEmail email = new HtmlEmail();
            email.setHostName(smtpHost);
            if (smtpPort != null && smtpPort.length() != 0) {
                email.setSmtpPort(Integer.parseInt(smtpPort));
            }
            if (smtpUsername != null && !smtpUsername.isEmpty()) {
                if (smtpPassword != null) {
                    smtpPassword = SecurityUtil.decrypt(smtpPassword);
                }
                email.setAuthentication(smtpUsername, smtpPassword);
            }
            if(security!= null){
                if(security.equalsIgnoreCase("SSL") ){
                    email.setSSL(true);
                }else if(security.equalsIgnoreCase("TLS")){
                    email.setTLS(true);
                }
            }
            if (cc != null && cc.length() != 0) {
                Collection<String> ccs = AppUtil.getEmailList(null, cc, wfAssignment, appDef);
                for (String address : ccs) {
                    email.addCc(address);
                }
            }

            final String fromStr = WorkflowUtil.processVariable(from, formDataTable, wfAssignment);
            email.setFrom(fromStr);
            email.setSubject(emailSubject);
            email.setCharset("UTF-8");
           
            if ("true".equalsIgnoreCase(isHtml)) {
                email.setHtmlMsg(emailMessage);
            } else {
                email.setMsg(emailMessage);
            }
            String emailToOutput = "";

            if ((toParticipantId != null && toParticipantId.trim().length() != 0) || (toSpecific != null && toSpecific.trim().length() != 0)) {
                Collection<String> tss = AppUtil.getEmailList(toParticipantId, toSpecific, wfAssignment, appDef);
                for (String address : tss) {
                    email.addTo(address);
                    emailToOutput += address + ", ";
                }
            } else {
                throw new PluginException("no email specified");
            }

            final String to = emailToOutput;
            final String profile = DynamicDataSourceManager.getCurrentProfile();
           
            //handle file attachment
            String formDefId = (String) properties.get("formDefId");
            Object[] fields = null;
            if (properties.get("fields") instanceof Object[]){
                fields = (Object[]) properties.get("fields");
            }
            if (formDefId != null && !formDefId.isEmpty() && fields != null && fields.length > 0) {
                AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
               
                FormData formData = new FormData();
                String primaryKey = appService.getOriginProcessId(wfAssignment.getProcessId());
                formData.setPrimaryKeyValue(primaryKey);
                Form loadForm = appService.viewDataForm(appDef.getId(), appDef.getVersion().toString(), formDefId, null, null, null, formData, null, null);
               
                for (Object o : fields) {
                    Map mapping = (HashMap) o;
                    String fieldId = mapping.get("field").toString();
                       
                    try {
                        Element el = FormUtil.findElement(fieldId, loadForm, formData);
                       
                        String value = FormUtil.getElementPropertyValue(el, formData);
                        if (value != null && !value.isEmpty()) {
                            File file = FileUtil.getFile(value, loadForm, primaryKey);
                            if (file != null) {
                                FileDataSource fds = new FileDataSource(file);
                                email.attach(fds, MimeUtility.encodeText(file.getName()), "");
                            }
                        }
                    } catch(Exception e){
                        LogUtil.info(EmailTool.class.getName(), "Attached file fail from field \"" + fieldId + "\" in form \"" + formDefId + "\"");
                    }
                }
            }
           
            Object[] files = null;
            if (properties.get("files") instanceof Object[]){
                files = (Object[]) properties.get("files");
            }
            if (files != null && files.length > 0) {
                for (Object o : files) {
                    Map mapping = (HashMap) o;
                    String path = mapping.get("path").toString();
                    String fileName = mapping.get("fileName").toString();
                    String type = mapping.get("type").toString();
                       
                    try {
                       
                        if ("system".equals(type)) {
                            EmailAttachment attachment = new EmailAttachment();
                            attachment.setPath(path);
                            attachment.setName(MimeUtility.encodeText(fileName));
                            email.attach(attachment);
                        } else {
                            URL u = new URL(path);
                            email.attach(u, MimeUtility.encodeText(fileName), "");
                        }
                       
                    } catch(Exception e){
                        LogUtil.info(EmailTool.class.getName(), "Attached file fail from path \"" + path + "\"");
                        e.printStackTrace();
                    }
                }
            }

            Thread emailThread = new Thread(new Runnable() {

                public void run() {
                    try {
                        HostManager.setCurrentProfile(profile);
                        LogUtil.info(EmailTool.class.getName(), "EmailTool: Sending email from=" + fromStr + ", to=" + to + "cc=" + cc + ", subject=" + email.getSubject());
                        email.send();
                        LogUtil.info(EmailTool.class.getName(), "EmailTool: Sending email completed for subject=" + email.getSubject());
                    } catch (EmailException ex) {
                        LogUtil.error(EmailTool.class.getName(), ex, "");
                    }
                }
            });
View Full Code Here

Examples of org.apache.commons.mail.HtmlEmail

            multiPartEmail = new MultiPartEmail();
            multiPartEmail.setMsg(mail.getBodyText());

        } else if (mail.getBodyText() == null || mail.getBodyText().equals("")) {
            multiPartEmail = new HtmlEmail().setHtmlMsg(mail.getBodyHtml());
        } else {
            multiPartEmail =
                    new HtmlEmail().setHtmlMsg(mail.getBodyHtml()).setTextMsg(mail.getBodyText());
        }

        // and return the nicely configured mail:
        return multiPartEmail;
    }
View Full Code Here

Examples of org.apache.commons.mail.HtmlEmail

    private VelocityEngine engine;

    private Email createEmail(boolean html) {
        Email e = null;
        if (html) {
            e = new HtmlEmail();
        } else {
            e = new SimpleEmail();
        }
        e.setHostName(smtpHost);
        if (!StringUtils.isEmpty(smtpUser)) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.