Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.io.PrintWriter;
- import java.net.Socket;
- public class SendBJBMail {
- public static void main (String[] args) throws Exception {
- while (true) {
- try (Socket s = new Socket("mail.devdoodle.net", 25)) {
- PrintWriter out = new PrintWriter(new OutputStreamWriter(s.getOutputStream(), "us-ascii"), true);
- BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream(), "us-ascii"), 1);
- command(null, in, null);
- command(out, in, "HELO nowhere.com");
- command(out, in, "MAIL FROM:nobody@nowhere.com");
- command(out, in, "RCPT TO:bjb568@devdoodle.net");
- command(out, in, "DATA");
- command(out, null, "Subject: OMG");
- command(out, null, "");
- command(out, null, "HAI");
- command(out, in, ".");
- command(out, in, "QUIT");
- } catch (Exception x) {
- System.out.flush();
- System.err.println(x.getClass().getSimpleName() + ": " + x.getMessage());
- }
- Thread.sleep(30000);
- }
- }
- static void command (PrintWriter out, BufferedReader in, String cmd) throws Exception {
- if (out != null) {
- System.out.println(">>> " + cmd);
- out.println(cmd);
- }
- if (in != null) {
- String response = in.readLine();
- System.out.println("<<< " + response);
- if (response.startsWith("4") || response.startsWith("5"))
- throw new Exception("SMTP command failed: " + response);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement