Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- int port = 465;
- String host = "smtp.gmail.com";
- try
- {
- Socket socket = new Socket(host, port);
- sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
- String username = encoder.encode("testing@gmail.com".getBytes());
- String password = encoder.encode("password".getBytes());
- DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
- DataInputStream isDI = new DataInputStream(socket.getInputStream());
- BufferedReader is = new BufferedReader(new InputStreamReader(isDI));
- dos.writeBytes("HELO\r\n");
- dos.writeBytes("AUTH LOGIN");
- dos.writeBytes("\r\n");
- dos.writeBytes(username);
- dos.writeBytes("\r\n");
- dos.writeBytes(password);
- dos.writeBytes("\r\n");
- dos.writeBytes("MAIL FROM:<testing@gmail.com>\r\n");
- dos.writeBytes("\r\n");
- dos.writeBytes("RCPT TO: <testing@gmail.com\r\n");
- dos.writeBytes("DATA\r\n");
- dos.writeBytes("Subject: Email test\r\n");
- dos.writeBytes("Test 1 2 3");
- dos.writeBytes("\r\n.\r\n");
- dos.writeBytes("QUIT\r\n");
- dos.flush();
- String responseline;
- while((responseline = is.readLine())!=null) {
- System.out.println(responseline);
- }
- is.close();
- dos.close( );
- socket.close( );
- }
- catch (IOException ex) {
- System.err.println(ex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement