⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendthread.java

📁 用JAVA语言实现JOB HUNTER的功能
💻 JAVA
字号:
package jobhunter;import jobhunter.ResumeSend.*;import java.net.*;import java.io.*;import java.util.*;import javax.mail.*;import javax.mail.internet.*;import javax.activation.*;public class SendThread extends Thread {  //private Queue ResumeSend.keyQue;  private int intN;  private int intT;  static private String from;  static private String smtphost;  static private String user;  static private String passwd;  static private String title;  static {    try{      BufferedReader br = new BufferedReader(new FileReader("jobhunter.conf"));      String paramLine;      String paramValue;      int i;      while((paramLine = br.readLine())!=null){        if((i = paramLine.indexOf("=")) != -1) {          if(paramLine.startsWith("from")){            from = paramLine.substring(i+1);          }else if(paramLine.startsWith("smtphost")){            smtphost = paramLine.substring(i+1);          }else if(paramLine.startsWith("user")){            user = paramLine.substring(i+1);          }else if(paramLine.startsWith("passwd")){            passwd = paramLine.substring(i+1);          }else if(paramLine.startsWith("title")){            title = paramLine.substring(i+1);          }        }      }    }catch(Exception e){      System.out.println(e);    }  }  public SendThread(int pIntN,int pIntT) {   // this.ResumeSend.keyQue = pKeyQue;    this.intN = pIntN;    this.intT = pIntT;  }  public void run() {    System.out.println("Prepare Email....");    //发送电子邮件,初始化    System.out.println("Sending From: "+from);    // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!    // Create properties, get Session    Properties props = System.getProperties();    // If using static Transport.send(),    // need to specify which host to send it to    props.put("mail.smtp.host", smtphost);    // To see what is going on behind the scene    //props.put("mail.debug", "true");    props.put("mail.smtp.auth", "true");    Session session = Session.getInstance(props, new SAuth());    try {      // Instantiatee a message      Message msg = new MimeMessage(session);      //Set message attributes      msg.setFrom(new InternetAddress(from));      msg.setSubject(title);//"应聘软件开发/技术支持");      msg.setSentDate(new Date());      // Set message content      //msg.setText("Text");      try {        collect("resume.txt", msg);      }      catch (Exception e) {        e.printStackTrace(System.out);        System.out.println("fail get file");        return;      }      //循环发送电子邮件      synchronized(ResumeSend.keyQue){        int NO = 1;        int waits = 0; Main:  while ((!(ResumeSend.keyQue.isEmpty()))||(ResumeSend.threads>0)) {          while((ResumeSend.keyQue.size()<10)&&(ResumeSend.threads>0)){            try{              if(waits==6) break Main;//等了30分钟还没结束就退出              waits++;              this.sleep(1000 * 60*5);            }catch(Exception e){              e.printStackTrace(System.out);            }            System.out.println("Wait For Search More "+ResumeSend.threads+" Emails...");          }          //间隔处理          this.sleep(intT * 1000);          int adds = ResumeSend.keyQue.size();          adds = adds < intN ? adds : intN;          if (adds > 0) {            InternetAddress[] address = new InternetAddress[adds];            for (int i = 0; i < adds; i++) {              String to = ResumeSend.keyQue.dequeue(); //"searockcliff@163.com";              try {                address[i] = new InternetAddress(to);              }              catch (Exception e) {                System.out.println(to + " is not an eamil address!");                e.printStackTrace(System.out);                i--;              }            }            msg.setRecipients(Message.RecipientType.BCC, address);//use BCC,other receivers can not be seen            try {              Transport.send(msg);            }            catch (Exception e) {              System.out.println("Missed 10 Emails!");              for (int en = 0; en < address.length; en++) {                System.out.print(address[en] + ";");              }              e.printStackTrace(System.out);            }            System.out.println( ( (NO - 1) * intN + adds) + " Mails Sent!");            NO++;          }          else {            break;          }        }//end while      }//synchronize      System.out.println("Mails Sent Over!");    }    catch (Exception e) {      e.printStackTrace();    }    //发送失败时邮件地址备份    try {      RandomAccessFile raf = null;      if (!ResumeSend.keyQue.isEmpty()) {        raf = new RandomAccessFile("Bemailsbak", "rw");      }      while (!ResumeSend.keyQue.isEmpty()) {        raf.write( (ResumeSend.keyQue.dequeue()).getBytes());        raf.write("\r\n".getBytes());      }    }    catch (Exception e) {      e.printStackTrace();    }  }  class SAuth extends javax.mail.Authenticator {    public javax.mail.PasswordAuthentication getPasswordAuthentication() {      return new javax.mail.PasswordAuthentication(          user, passwd);    }  }  public void collect(String fName, Message msg) throws MessagingException, IOException {    File f = new File(fName);    int len =Math.round(f.length());    FileInputStream in = new FileInputStream(fName);    BufferedInputStream bin= new BufferedInputStream(in);    byte[] buff= new byte[len];    bin.read(buff,0,buff.length);    msg.setText(new String(buff,"GBK"));  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -