Advertisement
Guest User

Untitled

a guest
Sep 12th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. public static void main(String[] args) {
  2.         int port = 465;
  3.         String host = "smtp.gmail.com";
  4.         try
  5.         {
  6.             Socket socket = new Socket(host, port);
  7.             sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
  8.             String username = encoder.encode("testing@gmail.com".getBytes());
  9.             String password = encoder.encode("password".getBytes());
  10.  
  11.             DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
  12.             DataInputStream isDI = new DataInputStream(socket.getInputStream());
  13.             BufferedReader is = new BufferedReader(new InputStreamReader(isDI));
  14.  
  15.             dos.writeBytes("HELO\r\n");
  16.             dos.writeBytes("AUTH LOGIN");
  17.             dos.writeBytes("\r\n");
  18.             dos.writeBytes(username);
  19.             dos.writeBytes("\r\n");
  20.             dos.writeBytes(password);
  21.             dos.writeBytes("\r\n");
  22.             dos.writeBytes("MAIL FROM:<testing@gmail.com>\r\n");
  23.             dos.writeBytes("\r\n");
  24.             dos.writeBytes("RCPT TO: <testing@gmail.com\r\n");
  25.             dos.writeBytes("DATA\r\n");
  26.             dos.writeBytes("Subject: Email test\r\n");
  27.             dos.writeBytes("Test 1 2 3");
  28.             dos.writeBytes("\r\n.\r\n");
  29.             dos.writeBytes("QUIT\r\n");
  30.  
  31.             dos.flush();
  32.  
  33.             String responseline;
  34.             while((responseline = is.readLine())!=null) {
  35.                     System.out.println(responseline);
  36.             }
  37.  
  38.             is.close();
  39.             dos.close( );                  
  40.             socket.close( );
  41.         }
  42.         catch (IOException ex) {
  43.             System.err.println(ex);
  44.         }
  45.        
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement