Advertisement
Guest User

Untitled

a guest
Mar 21st, 2015
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.io.OutputStreamWriter;
  4. import java.io.PrintWriter;
  5. import java.net.Socket;
  6.  
  7. public class SendBJBMail {
  8.    
  9.     public static void main (String[] args) throws Exception {
  10.      
  11.         while (true) {
  12.            
  13.             try (Socket s = new Socket("mail.devdoodle.net", 25)) {
  14.                 PrintWriter out = new PrintWriter(new OutputStreamWriter(s.getOutputStream(), "us-ascii"), true);
  15.                 BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream(), "us-ascii"), 1);
  16.                 command(null, in, null);
  17.                 command(out, in, "HELO nowhere.com");
  18.                 command(out, in, "MAIL FROM:nobody@nowhere.com");
  19.                 command(out, in, "RCPT TO:bjb568@devdoodle.net");
  20.                 command(out, in, "DATA");
  21.                 command(out, null, "Subject: OMG");
  22.                 command(out, null, "");
  23.                 command(out, null, "HAI");
  24.                 command(out, in, ".");
  25.                 command(out, in, "QUIT");
  26.             } catch (Exception x) {
  27.                 System.out.flush();
  28.                 System.err.println(x.getClass().getSimpleName() + ": " + x.getMessage());
  29.             }
  30.            
  31.             Thread.sleep(30000);
  32.            
  33.         }
  34.        
  35.     }
  36.    
  37.     static void command (PrintWriter out, BufferedReader in, String cmd) throws Exception {
  38.        
  39.         if (out != null) {
  40.             System.out.println(">>> " + cmd);
  41.             out.println(cmd);
  42.         }
  43.        
  44.         if (in != null) {
  45.             String response = in.readLine();
  46.             System.out.println("<<< " + response);
  47.             if (response.startsWith("4") || response.startsWith("5"))
  48.                 throw new Exception("SMTP command failed: " + response);
  49.         }
  50.        
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement