home *** CD-ROM | disk | FTP | other *** search
/ PC for Alla 2003 April / PFA0304.iso / fullversioner / ImageZoom / InstData / com / utility / Mail.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-07-17  |  2.4 KB  |  93 lines

  1. package com.zerog.ia.download.utility;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import java.net.Socket;
  7. import java.net.UnknownHostException;
  8.  
  9. public class Mail extends Thread {
  10.    String smtpServer;
  11.    String myName;
  12.    String fromAddress;
  13.    String toAddress;
  14.    String message;
  15.    Socket socketSmtpServer = null;
  16.    DataOutputStream dos = null;
  17.    DataInputStream dis = null;
  18.    boolean mailSent;
  19.    long timeoutSeconds = 8L;
  20.  
  21.    public Mail(String var1, String var2, String var3, String var4, String var5) {
  22.       this.smtpServer = var1;
  23.       this.myName = var2;
  24.       this.fromAddress = var3;
  25.       this.toAddress = var4;
  26.       this.message = var5;
  27.       ((Thread)this).setPriority(1);
  28.    }
  29.  
  30.    public boolean sendMail() {
  31.       this.mailSent = false;
  32.       ((Thread)this).start();
  33.       long var1 = System.currentTimeMillis();
  34.  
  35.       while(!this.mailSent && System.currentTimeMillis() - var1 < this.timeoutSeconds * 1000L) {
  36.          try {
  37.             Thread.sleep(500L);
  38.          } catch (Exception var4) {
  39.          }
  40.       }
  41.  
  42.       return this.mailSent;
  43.    }
  44.  
  45.    public void run() {
  46.       try {
  47.          this.makeConnection();
  48.       } catch (Exception var2) {
  49.          this.mailSent = false;
  50.       }
  51.  
  52.    }
  53.  
  54.    void makeConnection() throws Exception {
  55.       try {
  56.          this.socketSmtpServer = new Socket(this.smtpServer, 25);
  57.          this.dos = new DataOutputStream(this.socketSmtpServer.getOutputStream());
  58.          this.dis = new DataInputStream(this.socketSmtpServer.getInputStream());
  59.       } catch (UnknownHostException var4) {
  60.          throw var4;
  61.       } catch (IOException var5) {
  62.          throw var5;
  63.       }
  64.  
  65.       String var1 = this.dis.readLine();
  66.       this.dos.writeBytes("HELO " + this.myName + "\n");
  67.       var1 = this.dis.readLine();
  68.       this.dos.writeBytes("RSET\n");
  69.       var1 = this.dis.readLine();
  70.       this.dos.writeBytes("MAIL FROM:<" + this.fromAddress + ">\n");
  71.       this.dis.readLine();
  72.       this.dos.writeBytes("RCPT TO:<" + this.toAddress + ">\n");
  73.       this.dis.readLine();
  74.       this.dos.writeBytes("DATA\n");
  75.       var1 = this.dis.readLine();
  76.       this.dos.writeBytes("To: " + this.toAddress + "\n");
  77.       this.dos.writeBytes("From: " + this.fromAddress + "\n");
  78.       this.dos.writeBytes("Subject: InstallAnywhere Web Install Problem\n");
  79.       String var2 = "SimpleBoundary";
  80.       this.dos.writeBytes("Mime-Version 1.0\n");
  81.       this.dos.writeBytes("Content-Type: text/plain; charset=\"us-ascii\"\n\n");
  82.       this.dos.writeBytes(this.message);
  83.       this.dos.writeBytes("\n.\n");
  84.       var1 = this.dis.readLine();
  85.       this.dos.writeBytes("QUIT\n");
  86.       var1 = this.dis.readLine();
  87.       this.dos.close();
  88.       this.dis.close();
  89.       this.socketSmtpServer.close();
  90.       this.mailSent = true;
  91.    }
  92. }
  93.