示例#1
0
 /**
  * 发送模板邮件
  *
  * @param toMailAddr 收信人地址
  * @param subject email主题
  * @param templatePath 模板地址
  * @param map 模板map
  */
 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);
     System.out.println(htmlText);
     hemail.setMsg(htmlText);
     hemail.send();
     System.out.println("email send true!");
   } catch (Exception e) {
     e.printStackTrace();
     System.out.println("email send error!");
   }
 }
  @Asynchronous
  public void sendEmail(
      final String body,
      final String subject,
      List<String> recipients,
      final String from,
      List<String> attachment,
      boolean html) {

    if (recipients != null && !recipients.isEmpty()) {

      HtmlEmail email = new HtmlEmail();
      try {
        email.setHostName(MainConfig.EMAIL_SMTP_HOST);
        email.setSmtpPort(MainConfig.EMAIL_SMTP_PORT);
        if (!MainConfig.EMAIL_SMTP_USER.isEmpty() && !MainConfig.EMAIL_SMTP_PASSWORD.isEmpty()) {
          email.setAuthenticator(
              new DefaultAuthenticator(MainConfig.EMAIL_SMTP_USER, MainConfig.EMAIL_SMTP_PASSWORD));
        }
        email.setTLS(MainConfig.EMAIL_SMTP_TLS);

        email.setFrom(from, MainConfig.EMAIL_FROM, "UTF-8");
        email.setSubject(subject);
        email.setCharset("UTF-8");

        if (html) {
          email.setHtmlMsg(body);
        } else {
          email.setTextMsg(body);
        }

        for (String s : recipients) {
          email.addTo(s);
        }

        if (attachment != null && !attachment.isEmpty()) {
          for (String s : attachment) {
            EmailAttachment at = new EmailAttachment();
            at.setPath(s);
            at.setDisposition(EmailAttachment.ATTACHMENT);
            String parts[] = s.split("/");
            if (parts.length > 0) {
              at.setName(parts[parts.length - 1]);
            }
          }
        }

        email.send();
      } catch (Exception e) {
        logger.error("Can not send e-mail to " + recipients + " with subject: " + subject, e);
      }
    } else {
      logger.warn("Try send email with subject " + subject + " but recipients empty.");
    }
  }
  /**
   * Handle an event broadcast from another component
   *
   * @param event {@link org.blojsom.event.Event} to be handled
   */
  public void handleEvent(Event event) {
    if (event instanceof CommentAddedEvent) {
      HtmlEmail email = new HtmlEmail();
      CommentAddedEvent commentAddedEvent = (CommentAddedEvent) event;

      if (commentAddedEvent.getBlog().getBlogEmailEnabled().booleanValue() && _mailServer != null) {
        try {
          setupEmail(commentAddedEvent.getBlog(), commentAddedEvent.getEntry(), email);

          Map emailTemplateContext = new HashMap();
          emailTemplateContext.put(BlojsomConstants.BLOJSOM_BLOG, commentAddedEvent.getBlog());
          emailTemplateContext.put(
              BLOJSOM_COMMENT_PLUGIN_BLOG_COMMENT, commentAddedEvent.getComment());
          emailTemplateContext.put(BLOJSOM_COMMENT_PLUGIN_BLOG_ENTRY, commentAddedEvent.getEntry());

          String htmlText =
              mergeTemplate(
                  COMMENT_PLUGIN_EMAIL_TEMPLATE_HTML,
                  commentAddedEvent.getBlog(),
                  emailTemplateContext);
          String plainText =
              mergeTemplate(
                  COMMENT_PLUGIN_EMAIL_TEMPLATE_TEXT,
                  commentAddedEvent.getBlog(),
                  emailTemplateContext);

          email.setHtmlMsg(htmlText);
          email.setTextMsg(plainText);

          String emailPrefix =
              (String) commentAddedEvent.getBlog().getProperties().get(COMMENT_PREFIX_IP);
          if (BlojsomUtils.checkNullOrBlank(emailPrefix)) {
            emailPrefix = DEFAULT_COMMENT_PREFIX;
          }

          email =
              (HtmlEmail) email.setSubject(emailPrefix + commentAddedEvent.getEntry().getTitle());

          email.send();
        } catch (EmailException e) {
          if (_logger.isErrorEnabled()) {
            _logger.error(e);
          }
        }
      } else {
        if (_logger.isErrorEnabled()) {
          _logger.error(
              "Missing SMTP servername servlet initialization parameter: "
                  + EmailConstants.SMTPSERVER_IP);
        }
      }
    }
  }
 public void sendEmail() {
   try {
     List<Emails> emails = emailsDao.getEmailsByStatus('N');
     if (!ITeachUtility.isEmptyList(emails)) {
       for (Emails emailToSend : emails) {
         try {
           HtmlEmail email = new HtmlEmail();
           email.setHostName(ITeachUtility.getPropValue("hostName", true));
           email.setSmtpPort(Integer.parseInt(ITeachUtility.getPropValue("portNumber", true)));
           email.setAuthenticator(
               new DefaultAuthenticator(
                   ITeachUtility.getPropValue("userName", true),
                   ITeachUtility.getPropValue("password", true)));
           email.addTo(emailToSend.getEmailTo());
           email.setFrom(emailToSend.getEmailFrom(), emailToSend.getEmailFromName());
           email.setSubject(emailToSend.getEmailSub());
           String emailContent = emailToSend.getEmailBody();
           /*
            * if(StringUtils.isNotBlank(emailToSend.
            * getEmailAttachments ())){ Set<String>
            * attachments=ITeachUtility.getStringAsSet(emailToSend.
            * getEmailAttachments(), ","); }
            */
           // set the html message
           email.setHtmlMsg("<html>" + emailContent + "</html>");
           email.send();
           emailToSend.setSendAttempt(
               emailToSend.getSendAttempt() == null ? 1 : (emailToSend.getSendAttempt() + 1));
           emailToSend.setEmailStatus('S');
           emailToSend.setSentOn(Calendar.getInstance().getTime());
           System.out.println("sent email to " + emailToSend.getEmailTo());
         } catch (EmailException e) {
           // if any exception then updating the attempt.
           emailToSend.setSendAttempt(
               emailToSend.getSendAttempt() == null ? 1 : (emailToSend.getSendAttempt() + 1));
           e.printStackTrace();
         }
         emailsDao.updateEmails(emailToSend);
       }
     } else {
       System.out.println("No email to send.");
     }
   } catch (ITeachException ex) {
     ex.printStackTrace();
   }
 }
示例#5
0
 /**
  * 发送普通邮件
  *
  * @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!");
   }
 }
示例#6
0
  public void sendSmtpTestMail(
      String smtpFromMail,
      String smtpHost,
      Integer smtpPort,
      String smtpUsername,
      String smtpPassword,
      String toMail) {
    SystemConfig systemConfig = SystemConfigUtil.getSystemConfig();
    MailConfig mailConfig = TemplateConfigUtil.getMailConfig(MailConfig.SMTP_TEST);
    String subject = mailConfig.getSubject();
    String templateFilePath = mailConfig.getTemplateFilePath();
    try {
      email = new HtmlEmail();
      email.setHostName(systemConfig.getSmtpHost());
      email.setSmtpPort(systemConfig.getSmtpPort());
      email.setAuthenticator(
          new DefaultAuthenticator(systemConfig.getSmtpUsername(), systemConfig.getSmtpPassword()));
      email.setSSLOnConnect(true);

      WebAppResourceLoader resourceLoader = new WebAppResourceLoader();
      Configuration cfg = Configuration.defaultConfiguration();
      GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
      Template template = gt.getTemplate(templateFilePath);
      template.binding("systemConfig", systemConfig);
      String text = template.render();

      email.setFrom(
          MimeUtility.encodeWord(systemConfig.getShopName())
              + " <"
              + systemConfig.getSmtpFromMail()
              + ">");
      email.setSubject(subject);
      email.setMsg(text);
      email.addTo(toMail);
      email.send();

    } catch (EmailException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
示例#7
0
 public static void sendPromocao(Cotacao cotacao) {
   HtmlEmail email = new HtmlEmail();
   try {
     email.setHostName("mail.gentec.inf.br");
     email.setSmtpPort(587);
     email.setAuthentication("*****@*****.**", "123456");
     email.addTo("*****@*****.**");
     email.setFrom("*****@*****.**", "Pedido de Cota\347\343o");
     email.setCharset("ISO-8859-1");
     email.setSubject("Gentec IT");
     email.setHtmlMsg(
         (new StringBuilder("<html><body><h1> Empresa: "))
             .append(cotacao.getNomeEmpresa())
             .append("</h1>")
             .append("<br/>")
             .append("<div>")
             .append("Nome de Cliente: ")
             .append(cotacao.getNomeCliente())
             .append("<br/>")
             .append("CNPJ: ")
             .append(cotacao.getNumeroCnpj())
             .append("<br/>")
             .append("Telefone: ")
             .append(cotacao.getNumeroTelefone())
             .append("<br/>")
             .append("E-mail: ")
             .append(cotacao.getEmail())
             .append("<br/>")
             .append("Observa\347\365es: ")
             .append(cotacao.getObservacoes())
             .append("<br/>")
             .append("</div>")
             .append("</body>")
             .append("</html>")
             .toString());
     email.setTextMsg("Seu servidor de e-mail n\343o suporta mensagem HTML");
     email.send();
   } catch (EmailException e) {
     e.printStackTrace();
   }
 }
示例#8
0
  public boolean sendMail(
      String subject, String templateFilePath, Map<String, Object> data, String toMail) {
    boolean isSend = false;
    try {
      SystemConfig systemConfig = SystemConfigUtil.getSystemConfig();

      email = new HtmlEmail();
      email.setHostName(systemConfig.getSmtpHost());
      email.setSmtpPort(systemConfig.getSmtpPort());
      email.setAuthenticator(
          new DefaultAuthenticator(systemConfig.getSmtpUsername(), systemConfig.getSmtpPassword()));
      email.setSSLOnConnect(true);

      WebAppResourceLoader resourceLoader = new WebAppResourceLoader();
      Configuration cfg = Configuration.defaultConfiguration();
      GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
      Template template = gt.getTemplate(templateFilePath);
      template.binding(data);
      String text = template.render();

      email.setFrom(
          MimeUtility.encodeWord(systemConfig.getShopName())
              + " <"
              + systemConfig.getSmtpFromMail()
              + ">");
      email.setSubject(subject);
      email.setMsg(text);
      email.addTo(toMail);
      email.send();
      isSend = true;
    } catch (EmailException e) {
      e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return isSend;
  }
示例#9
0
  private void sendFailedJobEmail(TnrsJob job) throws Exception {
    if (!job.email()) return;

    HtmlEmail response = new HtmlEmail();
    response.setHostName("localhost");
    response.setSmtpPort(25);
    response.setFrom("*****@*****.**");
    response.setSubject("TNRS Job failure");
    response.setMsg(
        "Your TNRS "
            + job.getTypeString()
            + " job for the file "
            + job.getRequest().getOriginalFilename()
            + " failed on "
            + dateFormat.format(new Date())
            + ". Please provide the job key and if possible the name list you were runing so we can better help you diagnose the issue.	\n\n"
            + "The job key is:"
            + job.getRequest().getId()
            + "\n\n"
            + "Thank you,\n"
            + "iPlant Collaborative");
    response.addTo(job.getRequest().getEmail());
    response.send();
  }
示例#10
0
  public void sendHtmlMail(String toEmail, String HtmlMsg) {

    HtmlEmail email = new HtmlEmail();

    email.setCharset("UTF-8");
    email.setHostName("smtp.sina.com");
    email.setSmtpPort(25);
    email.setAuthentication("*****@*****.**", "tianren");
    email.setTLS(true);

    try {
      email.addTo(toEmail);

      email.setFrom("*****@*****.**");
      email.setSubject("Sky Movie"); // Title
      email.setMsg("Ticket Order Info");

      URL url = new URL("http://localhost:8888/TianRen/uploadAd/31049534581071.gif");
      String cid = email.embed(url, "TianRen Logo");

      email.setHtmlMsg(
          "<html><a href='http://localhost:8888/TianRen/index.jsp'><img src=\"cid:"
              + cid
              + "\" height=\"75\"></a><br/>"
              + HtmlMsg
              + "</html>");

      email.send();
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (EmailException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public boolean sendRegistartionConfirmationMail(QuasarMailConfiguration qmc, String... emailids) {
    try {
      HtmlEmail email = new HtmlEmail();
      email.setHostName(qmc.getHost());
      email.setSmtpPort(Integer.parseInt(qmc.getPort()));
      email.setAuthentication(qmc.getAdimnusername(), qmc.getAdminpassword());
      email.setSSLOnConnect(Boolean.parseBoolean(qmc.getStarttls()));

      email.setFrom(qmc.getAdimnusername());

      email.setSubject("TestMail");

      // MailChimp
      // email.setHtmlMsg("<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Insert
      // title here</title></head><body><table id=\"studentdetail\" style=\"background-color:
      // graytext;font-family: sans-serif;padding: 10px;-webkit-border-radius:
      // 4px;-moz-border-radius: 4px;border-radius: 4px;box-shadow: 0 4px 4px -4px rgba(0, 0, 0,
      // 0.7);-moz-box-shadow: 0 4px 4px -4px rgba(0, 0, 0, 0.7);-webkit-box-shadow: 0 4px 6px -5px
      // rgba(0, 0, 0, 0.8);\"><tr><td align=\"center\"><img alt=\"alt\"
      // src=\"images/logo.png\"></td><td align=\"left\">CMC LTD,New Delhi,Near Kohat Enclave Metro
      // Station</td></tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<p>Grettings, Thanks for registering
      // at CMC Delhi. We wish you a prosperous learning.If you any query click on this link <a
      // href=\"www.cmcdelhi.com\">Link</a></p></td></tr></table></body></html>");
      email.setHtmlMsg(
          "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Insert title here</title></head><body>"
              + "<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"100%\" width=\"100%\" style=\"border-collapse:collapse;margin:0;padding:0;background-color:#f2f2f2;height:100%!important;width:100%!important\"><tbody><tr><td align=\"center\" valign=\"top\" style=\"margin:0;padding:0;border-top:5px none #aaaaaa;height:100%!important;width:100%!important\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse:collapse\"><tbody>"
              + "<tr><td align=\"center\" valign=\"top\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse: collapse; background-color: #ffffff; border-top: 0; border-bottom: 0\"><tbody><tr><td align=\"center\" valign=\"top\">"
              + "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\"style=\"border-collapse: collapse\"><tbody>	<tr><td valign=\"top\" style=\"padding-top: 10px; padding-bottom: 10px\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse: collapse\">"
              + "<tbody><tr><td valign=\"top\" style=\"padding: 9px\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"width=\"100%\" style=\"border-collapse: collapse\"><tbody><tr><td valign=\"top\" style=\"padding: 9px\"><table align=\"left\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\"><tbody><tr><td valign=\"top\"><ahref=\"http://www.cmcdelhi.com/\" "
              + "title=\"\" style=\"word-wrap: break-word\" target=\"_blank\"><img alt=\"\" src=\"https://ci6.googleusercontent.com/proxy/RuvteIJkgNFYdxI6145X-lK4685AcOQxFui4iZxVKwtCz-hegVDIxdtSQ5PaGoE4fLQ_CR3uYlTuRNK8beuUu2loSM5gODacK1JsUqlEZ2lW2plIlZyyKfBPpqg6wpNywbTmDYca7UhlSa20h1k82LH1zIrVEMkqneme9Q=s0-d-e1-ft#http://gallery.mailchimp.com/38e8f39f127b52b8859e52f7c/images/4ea87a8b-6945-477c-904b-bbce8bf80a91.jpg\" width=\"116\" style=\"max-width: 116px; border: 0; outline: none; text-decoration: none; vertical-align: bottom\"></a></td></tr></tbody></table><table align=\"right\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"176\"style=\"border-collapse: collapse\"><tbody><tr><td valign=\"top\" style=\"font-family: Georgia, Times, 'Times New Roman', serif; font-size: 9px; font-style: normal; text-align: center; color: #606060; line-height: 150%\"><spanstyle=\"color: #000000; font-family: arial, helvetica, clean, sans-serif; font-size: small; line-height: 16.003000259399414px; text-align: -webkit-center\">8,Vaishali Enclave,Main Metro Road,&nbsp;</span><br style=\"font-size: small; color: #000000; font-family: arial, helvetica, clean, sans-serif; line-height: 16.003000259399414px; text-align: -webkit-center\">"
              + "<span style=\"color: #000000; font-family: arial, helvetica, clean, sans-serif; font-size: small; line-height: 16.003000259399414px; text-align: -webkit-center\">PitamPura,(Opp. Metro Pillar No. 351), New Delhi-110034,</span><br style=\"font-size: small; color: #000000; font-family: arial, helvetica, clean, sans-serif; line-height: 16.003000259399414px; text-align: -webkit-center\"><span style=\"color: #000000; font-family: arial, helvetica, clean, sans-serif; font-size: small; line-height: 16.003000259399414px; text-align: -webkit-center\">India</span></td></tr></tbody>	</table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr>"
              + "<tr><td align=\"center\" valign=\"top\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse:collapse;background-color:#ffffff;border-top:0;border-bottom:0\"><tbody><tr><td align=\"center\" valign=\"top\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\" style=\"border-collapse:collapse\"><tbody><tr><td valign=\"top\" style=\"padding-top:10px;padding-bottom:10px\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse:collapse\"><tbody><tr><td valign=\"top\"><table align=\"left\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\" style=\"border-collapse:collapse\"><tbody><tr> <td valign=\"top\" style=\"padding:9px 18px;font-size:9px;color:#606060;font-family:Helvetica;line-height:150%;text-align:left\">"
              + "<h1 style=\"margin:0;padding:0;display:block;font-family:Helvetica;font-size:32px;font-style:normal;font-weight:bold;line-height:125%;letter-spacing:-1px;text-align:left;color:#606060!important\">Greetings From CMC Delhi</h1><h3 style=\"margin:0;padding:0;display:block;font-family:Helvetica;font-size:14px;font-style:normal;font-weight:bold;line-height:125%;letter-spacing:-.5px;text-align:left;color:#606060!important\">Registration Confirmation Email</h3><p style=\"margin:1em 0;padding:0;color:#606060;font-family:Helvetica;font-size:15px;line-height:150%;text-align:left\">Thanks for registering at CMC Delhi.This is system generated mail confirming your registration for course #####.Wishing you a prosperous learning.<br>Get your payment details here &lt;a href=\"<a href=\"http://www.cmcdelhi.com\" target=\"_blank\">www.cmcdelhi.com</a>\"</p>"
              + "<p style=\"margin:1em 0;padding:0;color:#606060;font-family:Helvetica;font-size:15px;line-height:150%;text-align:left\">Need inspiration for your design? <a href=\"http://inspiration.mailchimp.com\" style=\"word-wrap:break-word;color:#6dc6dd;font-weight:normal;text-decoration:underline\" target=\"_blank\">Here�s what other MailChimp users are doing.</a></p></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr>"
              + "<tr><td align=\"center\" valign=\"top\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse:collapse;background-color:#f2f2f2;border-top:0;border-bottom:0\"><tbody><tr><td align=\"center\" valign=\"top\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\" style=\"border-collapse:collapse\"><tbody><tr><td valign=\"top\" style=\"padding-top:10px;padding-bottom:10px\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse:collapse\"><tbody><tr><td valign=\"top\"><table align=\"left\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\" style=\"border-collapse:collapse\"><tbody><tr>"
              + "<td valign=\"top\" style=\"padding-top:9px;padding-right:18px;padding-bottom:9px;padding-left:18px;color:#606060;font-family:Helvetica;font-size:11px;line-height:125%;text-align:left\"><em>Copyright � *|####YEAR#####|* CMC Delhi, All rights reserved.</em><br><br><strong>Our address :</strong><br><span style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\">8,Vaishali Enclave,Main Metro Road,&nbsp;</span><br style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\"><span style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\">"
              + "Pitam Pura,(Opp. Metro Pillar No. 351), New Delhi-110034,</span><br style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\"><span style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\">India</span><br><strong style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\">For Corporate Queries/College Tie-ups :&nbsp;Ashish Arora&nbsp; (09810324822)&nbsp;</strong><br style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\">"
              + "<strong style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\">For Student Queries:&nbsp;</strong><span style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\">Ms. Sabia Rais / Ms. Priyanka:09313877528, 01165905335 &amp; 65655335</span><br><strong style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\">E-mail:</strong><a href=\"mailto:[email protected]\" style=\"color:blue;text-decoration:none;font-weight:bold;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center;word-wrap:break-word\" target=\"_blank\">"
              + "[email protected]</a><span style=\"color:#000000;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center\">/</span><a href=\"mailto:[email protected]\" style=\"color:blue;text-decoration:none;font-weight:bold;font-family:arial,helvetica,clean,sans-serif;font-size:small;line-height:16.003000259399414px;text-align:-webkit-center;word-wrap:break-word\" target=\"_blank\">ashis<wbr>[email protected]</a><br>&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr>"
              + "</tbody></table></body></html>");
      // /Email Attachment
      // EmailAttachment attachment = new EmailAttachment();
      // attachment.setPath("/home/guffy/Pictures/fggsa.jpg");
      // attachment.setDisposition(EmailAttachment.ATTACHMENT);
      // attachment.setDescription("Picture of JMosque");
      // attachment.setName("Mousque");

      // email.attach(attachment);

      // set the alternative message
      email.setTextMsg("Your email client does not support HTML messages");

      // adding up the recivers
      for (String em : emailids) {
        // email.addTo("*****@*****.**");
        email.addTo(em);
      }

      email.send();

      return true;

    } catch (EmailException e) {
      Log.e("Email Exception : " + e.getMessage());

    } catch (Exception e) {
      Log.e("Exception : " + e.getMessage());
    }
    return false;
  }
示例#12
0
 @Signature
 public String send(PEmailBackend backend) throws EmailException {
   backend._apply(htmlEmail);
   return htmlEmail.send();
 }
示例#13
0
  public static void sendResetPwdMail(String appCode, ODocument user) throws Exception {
    final String errorString = "Cannot send mail to reset the password: "******" invalid user object");

    // initialization
    String siteUrl = Application.NETWORK_HTTP_URL.getValueAsString();
    int sitePort = Application.NETWORK_HTTP_PORT.getValueAsInteger();
    if (StringUtils.isEmpty(siteUrl))
      throw new PasswordRecoveryException(errorString + " invalid site url (is empty)");

    String textEmail = PasswordRecovery.EMAIL_TEMPLATE_TEXT.getValueAsString();
    String htmlEmail = PasswordRecovery.EMAIL_TEMPLATE_HTML.getValueAsString();
    if (StringUtils.isEmpty(htmlEmail)) htmlEmail = textEmail;
    if (StringUtils.isEmpty(htmlEmail))
      throw new PasswordRecoveryException(errorString + " text to send is not configured");

    boolean useSSL = PasswordRecovery.NETWORK_SMTP_SSL.getValueAsBoolean();
    boolean useTLS = PasswordRecovery.NETWORK_SMTP_TLS.getValueAsBoolean();
    String smtpHost = PasswordRecovery.NETWORK_SMTP_HOST.getValueAsString();
    int smtpPort = PasswordRecovery.NETWORK_SMTP_PORT.getValueAsInteger();
    if (StringUtils.isEmpty(smtpHost))
      throw new PasswordRecoveryException(errorString + " SMTP host is not configured");

    String username_smtp = null;
    String password_smtp = null;
    if (PasswordRecovery.NETWORK_SMTP_AUTHENTICATION.getValueAsBoolean()) {
      username_smtp = PasswordRecovery.NETWORK_SMTP_USER.getValueAsString();
      password_smtp = PasswordRecovery.NETWORK_SMTP_PASSWORD.getValueAsString();
      if (StringUtils.isEmpty(username_smtp))
        throw new PasswordRecoveryException(errorString + " SMTP username is not configured");
    }
    String emailFrom = PasswordRecovery.EMAIL_FROM.getValueAsString();
    String emailSubject = PasswordRecovery.EMAIL_SUBJECT.getValueAsString();
    if (StringUtils.isEmpty(emailFrom))
      throw new PasswordRecoveryException(errorString + " sender email is not configured");

    try {
      String userEmail =
          ((ODocument) user.field(UserDao.ATTRIBUTES_VISIBLE_ONLY_BY_THE_USER))
              .field("email")
              .toString();

      String username = (String) ((ODocument) user.field("user")).field("name");

      // Random
      String sRandom = appCode + "%%%%" + username + "%%%%" + UUID.randomUUID();
      String sBase64Random = new String(Base64.encodeBase64(sRandom.getBytes()));

      // 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);

      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")
                .append("Message: ")
                .append(email.toString())
                .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) {
      Logger.error("ERROR SENDING MAIL:" + ExceptionUtils.getStackTrace(e));
      throw new Exception(errorString, e);
    }
  }
示例#14
0
  public void sendEmailConfirmation(
      String reportUrl, WoParametri woParametri, User user, List<String> fakture) {
    try {
      List<String> emails = new ArrayList<String>();
      if (user.getWoPartnerSetting() != null
          && user.getWoPartnerSetting().get(0) != null
          && user.getWoPartnerSetting().get(0).getReceiveConfirm() == 1
          && user.getWoPartnerSetting().get(0).getEmailAddress() != null) {
        emails.add(user.getWoPartnerSetting().get(0).getEmailAddress());
      }
      if (user.getWoUserHasRights() != null
          && user.getWoUserHasRights().get("EMP") != null
          && user.getWoUserHasRights().get("EMP")
          && user.getWoUser() != null
          && user.getWoUser().getEmail() != null) {
        if (emails.size() == 0
            || (emails.size() > 0 && !emails.get(0).equals(user.getWoUser().getEmail())))
          emails.add(user.getWoUser().getEmail());
      }

      if ("INTERNI".equals(user.getWoUser().getUserType()) && user.getWoUser().getEmail() != null) {
        emails.add(user.getWoUser().getEmail());
      }

      if (emails.size() > 0) {
        String emailContent =
            woParametri
                .getConfirmMailContent()
                .substring(1, Integer.valueOf(woParametri.getConfirmMailContent().length() + ""));
        log.info(
            "Prametri su "
                + woParametri.getMailServerPort()
                + " "
                + woParametri.getMailaddress()
                + " "
                + woParametri.getMailserver()
                + " "
                + woParametri.getPassword());
        HtmlEmail email = new HtmlEmail();
        email.setHostName(woParametri.getMailserver());
        email.setSmtpPort(woParametri.getMailServerPort());
        email.setCharset("Windows-1250");
        // email.setDebug(true);
        if (woParametri.getWomailaddress() != null && woParametri.getPassword() != null) {
          email.setStartTLSRequired(true); // obavezno u slucaju gmail-a
          email.setAuthenticator(
              new DefaultAuthenticator(woParametri.getWomailaddress(), woParametri.getPassword()));
        }
        String[] sendTo = new String[emails.size()];
        for (int i = 0; i < emails.size(); i++) {
          System.out.println(emails.get(i));
          sendTo[i] = emails.get(i);
        }
        email.addTo(sendTo);
        email.setFrom(woParametri.getMailaddress(), "WebOrdering");
        email.setSubject("Potvrda porudžbine...");

        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(reportUrl);
        for (String idDokumenta : fakture) {
          List<NameValuePair> parameters = new ArrayList<NameValuePair>();
          parameters.add(new BasicNameValuePair("idDokumenta", idDokumenta));
          UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, HTTP.UTF_8);
          post.setEntity(sendentity);
          HttpResponse postResponse = client.execute(post);
          email.attach(
              new ByteArrayDataSource(postResponse.getEntity().getContent(), "application/pdf"),
              idDokumenta + ".pdf",
              "Document description",
              EmailAttachment.ATTACHMENT);
        }
        // embed the image and get the content id
        // String cid = email.embed("http://www.apache.org/images/asf_logo_wide.gif", "Apache
        // logo");
        // set the html message
        // email.setHtmlMsg("<html> Bla bla truc truc <br><br><br> <img src=\"cid:" + cid +
        // "\"></html>");
        // email.setHtmlMsg("<html><font face='verdana' color='#e26f16'><b>" + emailContent +
        // "</b></font></html>");
        email.setHtmlMsg(emailContent);
        email.send();
      }
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }
  }
示例#15
0
  public static void mailConfirmation(UsuarioSistema user, String uuid) throws EmailException {
    HtmlEmail email = new HtmlEmail();
    email.setHostName("localhost");
    email.setSmtpPort(25);
    email.setAuthentication("*****@*****.**", "");
    email.setSSLOnConnect(false);
    email.setFrom("*****@*****.**", "RedPG");
    email.setSubject("RedPG - Confirmação de e-mail");
    email.addTo(user.getEmail());

    email.setTextMsg(
        "Olá, "
            + user.getName()
            + ".\n\n"
            + "Obrigado por se registrar no sistema!\n\n"
            + "Para começar a utilizar o sistema, é necessário ativar a sua conta.\n"
            + "Você pode fazer isso seguindo o link a seguir:\n"
            + "http://redpg.com.br/index.html?confirm#"
            + uuid
            + "\n\nCaso esse link não funcione para você, acesse: \n"
            + "http://redpg.com.br/service/ActivateAccount.jsp?lingo=pt_br \n"
            + "E digite o código: \n"
            + uuid
            + "\n\nPara ativar sua conta. Você não poderá utilizar sua conta até a ativar por um dos links acima."
            + "\n\n\nObrigado por ter registrado sua conta!");

    email.setHtmlMsg(
        "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
            + "<html>\n"
            + "    <head>\n"
            + "        <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n"
            + "    </head>\n"
            + "    <body style=\"margin: 0px;\">\n"
            + "        <div style=\"width: 100%; height: 100%; display: table\">\n"
            + "            <div style=\"display: table-cell; width: 100%; height: 100%; background-color: #b2b9cf; border: solid 1px #000; text-align: center; vertical-align: middle\">\n"
            + "                <div style='display: block; width: 100%; text-align: center'>\n"
            + "                    <p style='font-size: 3em; margin: 20px; font-variant: small-caps'>RedPG</p>\n"
            + "                </div>\n"
            + "                <div style=\"display:inline-block; width: 80%; height: 300px; margin-bottom: 20px; background-color: white; border: solid 2px black;\">\n"
            + "                    <p>Olá, "
            + user.getName()
            + ".</p>\n"
            + "                    <p>&nbsp;</p>\n"
            + "                    <p>Obrigado por se registrar no sistema!</p>\n"
            + "                    <p>Para começar a utilizar o sistema, é necessário ativar a sua conta.\n"
            + "                    <p>Você pode fazer isso seguindo o link a seguir:</p>\n"
            + "                    <p><a href='http://redpg.com.br/index.html?confirm#"
            + uuid
            + "' target='_blank'>http://redpg.com.br/app/index.html?confirm#"
            + uuid
            + "</a></p>\n"
            + "<p>Caso o link acima não funcione, acesse:</p>"
            + "<p><a href='http://redpg.com.br/service/ActivateAccount.jsp?lingo=pt_br' target='_blank'>http://redpg.com.br/service/ActivateAccount.jsp?lingo=pt_br</a>"
            + "<p>E digite o código:</p>"
            + "<p>"
            + uuid
            + "</p>"
            + "<p>Para ativar sua conta. Você não poderá utilizar sua conta antes de seguir esses passos.</p>"
            + "                    <p style='margin-top: 20px;'>Obrigado por ter registrado sua conta!</p>\n"
            + "                </div>\n"
            + "            </div>\n"
            + "        </div>\n"
            + "    </body>\n"
            + "</html>");

    email.send();
  }