Exemple #1
0
  @Test
  public void test() {
    BaseApplicationContext context =
        DefaultApplicationContext.getApplicationContext("com/sany/mail/property-mail.xml");
    SendMail sendMail = context.getTBeanObject("sendMail", SendMail.class);
    sendMail.sendTextMail(new String[] {"*****@*****.**"}, "你好", "很好,很强大!");
    String content =
        " <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"96\">"
            + "<tr>"
            + "<td width=\"24%\" height=\"94\"><a href='http://ippresource.sany.com.cn/qikan/html/2013-04/29/node_1.htm' target='_blank'><img width='80' height='90' border='0' src='uploadfiles/201207/20120731060411867.jpg'></a></td>"
            + "<td width=\"76%\" valign=\"top\"><div><strong>三一集团报</strong></div>"
            + "<div><span class=\"red\">三一集团报</span> <a href=\"javascript:void('0')\" onclick=\"showPdf('http://ippresource.sany.com.cn/qikan/html/2013-04/29/node_1.htm')\">浏览</a>|<a href='brands/magazine/default.htm' target='_blank'>更多 >></a></div>"
            + "<div>做一流企业,办一流企业报。《三一集团》报1999年创刊,它见证记载了三一发展的艰辛和辉煌。</div></td>"
            + "</tr>"
            + "</table>";

    sendMail.sendHtmlMail(new String[] {"*****@*****.**"}, "你好html", content);
    sendMail.sendAttach(
        new String[] {"*****@*****.**"},
        "你好html",
        content,
        new String[] {
          "D:\\workspace\\SanyPDP\\resources\\org\\frameworkset\\task\\quarts-task.xml"
        });
  }
  public void finalsave(String card, Order order) {

    ArrayList<Order> buffer = new ArrayList<Order>();

    try {
      FileInputStream fileIn =
          new FileInputStream("C:\\apache-tomcat-7.0.34/temp/YourHotel/user/" + user + ".ser");
      ObjectInputStream in = new ObjectInputStream(fileIn);
      ui = (UserInfo) in.readObject();
      buffer = ui.order;
      in.close();
      fileIn.close();

    } catch (IOException i) {
      i.printStackTrace();

    } catch (ClassNotFoundException c) {
      System.out.println("User can not found");
      c.printStackTrace();
    }

    buffer.add(order);
    ui.card = card;
    ui.order = buffer;

    try {

      // File f = File.createTempFile(item.getItemID(), ".ser");

      File path = new File("C:\\apache-tomcat-7.0.34/temp/YourHotel/user/");

      if (!path.exists()) {
        path.mkdir();
      }

      File f = new File(path, user + ".ser");
      if (!f.exists()) {
        f.createNewFile();
      }

      FileOutputStream fileOut = new FileOutputStream(f);

      ObjectOutputStream out = new ObjectOutputStream(fileOut);
      out.writeObject(ui);
      out.close();
      fileOut.close();

      System.out.println("Serialized data is saved in " + f.getAbsolutePath());
      SendMail s = new SendMail();
      s.send(1, ui);

    } catch (IOException i1) {
      i1.printStackTrace();
    }
  }
 protected DCServerFactory.ResultCode sendEmail(
     String frEmail, String toEmail, String subj, String body) {
   if (StringTools.isBlank(frEmail)) {
     Print.logError("'From' Email address not specified");
     return DCServerFactory.ResultCode.TRANSMIT_FAIL;
   } else if (StringTools.isBlank(toEmail) || !CommandPacketHandler.validateAddress(toEmail)) {
     Print.logError("'To' SMS Email address invalid, or not specified");
     return DCServerFactory.ResultCode.TRANSMIT_FAIL;
   } else if (StringTools.isBlank(subj) && StringTools.isBlank(body)) {
     Print.logError("Command string not specified");
     return DCServerFactory.ResultCode.INVALID_ARG;
   } else {
     try {
       Print.logInfo("SMS email: to <" + toEmail + ">");
       Print.logDebug("  From   : " + frEmail);
       Print.logDebug("  To     : " + toEmail);
       Print.logDebug("  Subject: " + subj);
       Print.logDebug("  Message: " + body);
       SendMail.send(frEmail, toEmail, null, null, subj, body, null);
       return DCServerFactory.ResultCode.SUCCESS;
     } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
       // this will fail if JavaMail support for SendMail is not available.
       Print.logWarn("SendMail error: " + t);
       return DCServerFactory.ResultCode.TRANSMIT_FAIL;
     }
   }
 }
Exemple #4
0
 /* validate the syntax of the specified list of multiple email addresses */
 public static boolean validateAddresses(String addrs, boolean acceptSMS) {
   if (StringTools.isBlank(addrs)) {
     // blank is ok in this case
     return true;
   } else if (acceptSMS) {
     // allow "sms:123456789" format
     String addrArry[] = StringTools.parseStringArray(addrs, ',');
     if (addrArry.length == 0) {
       return false;
     }
     for (int i = 0; i < addrArry.length; i++) {
       String em = addrArry[i].trim();
       if (StringTools.isBlank(em)) {
         // individual addresses not allowed
         return false;
       } else if (SMSOutboundGateway.StartsWithSMS(em)) {
         // TODO: for now, accept as-is
       } else if (!validateAddress(em)) {
         return false;
       }
     }
     return true;
   } else {
     // true email addresses only
     try {
       return SendMail.validateAddresses(addrs);
     } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
       // this will fail if JavaMail support for SendMail is not available.
       Print.logError("*** SendMail error: " + t);
       return false;
     }
   }
 }
Exemple #5
0
 private String getEmail() {
   RTProperties rtp = this.getProperties();
   String email = rtp.getString(PROP_email, null);
   if (StringTools.isBlank(email)) {
     email = SendMail.getUserFromEmailAddress();
   }
   return email;
 }
Exemple #6
0
 /* extract email address from the specified string */
 public static String getEMailAddress(String addr) {
   // extract/normalize email address
   try {
     return SendMail.getEMailAddress(addr);
   } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
     // this will fail if JavaMail support for SendMail is not available.
     Print.logWarn("SendMail error: " + t);
     return null;
   }
 }
Exemple #7
0
 public static void sendMail(String subject, String content, String format) {
   MailSenderInfo mailInfo = new MailSenderInfo();
   mailInfo.setMailServerHost("sl2k8mail-01.dangdang.com");
   mailInfo.setMailServerPort("587");
   mailInfo.setValidate(true);
   mailInfo.setUserName("*****@*****.**");
   mailInfo.setPassword("Sl-1234"); // 您的邮箱密码
   mailInfo.setFromAddress("*****@*****.**");
   mailInfo.setToAddress("*****@*****.**");
   //	     mailInfo.setCcAddress("*****@*****.**");
   //	     mailInfo.setCcAddress("[email protected]; [email protected]");
   //	     mailInfo.setBccAddress("*****@*****.**");
   mailInfo.setSubject(subject);
   mailInfo.setContent(content);
   SendMail sms = new SendMail();
   if (format.equals("TEXT")) {
     sms.sendTextMail(mailInfo); // 发送文体格式
   } else if (format.equals("HTML")) {
     sms.sendHtmlMail(mailInfo); // 发送html格式
   }
 }
Exemple #8
0
 /* validate the syntax of the specified single email address */
 public static boolean validateAddress(String addr) {
   if (StringTools.isBlank(addr)) {
     // blanks not alowed here
     return false; // fail quickly
   } else {
     try {
       return SendMail.validateAddress(addr);
     } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
       // this will fail if JavaMail support for SendMail is not available.
       Print.logWarn("SendMail error: " + t);
       return false;
     }
   }
 }
Exemple #9
0
 /* send an email  with attachment */
 public static boolean send(
     String from,
     String to,
     String cc,
     String bcc,
     String subject,
     String msgBody,
     SendMail.SmtpProperties smtpProps,
     SendMail.Attachment attach) {
   try {
     return SendMail.send(from, to, cc, bcc, subject, msgBody, attach, smtpProps);
   } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
     // this will fail if JavaMail support for SendMail is not available.
     Print.logWarn("SendMail error: " + t);
     return false;
   }
 }