Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java socket connect to gmail

public class TotalTemp
{
     private static DataOutputStream dos;

     public static void main(String[] args) throws Exception
     {
          int delay = 1000;
          String user = "xxxxx@gmail.com";
          String pass = "xxxxxxxx11";
          String username = Base64.encodeBase64String(user.getBytes(StandardCharsets.UTF_8));
          String password = Base64.encodeBase64String(pass.getBytes(StandardCharsets.UTF_8));    

          SSLSocket sock = (SSLSocket)((SSLSocketFactory)SSLSocketFactory.getDefault()).createSocket("smtp.gmail.com", 465);
//          Socket sock = new Socket("smtp.gmail.com", 587);
          final BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
          (new Thread(new Runnable()
          {
               public void run()
               {
                    try
                    {
                         String line;
                         while((line = br.readLine()) != null)
                              System.out.println("SERVER: "+line);
                    }
                    catch (IOException e)
                    {
                         e.printStackTrace();
                    }
               }
          })).start();
          dos = new DataOutputStream(sock.getOutputStream());

          send("EHLO smtp.gmail.com
");
          Thread.sleep(delay);
          send("AUTH LOGIN
");
          Thread.sleep(delay);
          send(username + "
");
          Thread.sleep(delay);
          send(password + "
");
          Thread.sleep(delay);
          send("MAIL FROM:<XXXXXXXX@gmail.com>
");
          //send("
");
          Thread.sleep(delay);
          send("RCPT TO:<YYYYYYYY@gmail.com>
");
          Thread.sleep(delay);
          send("DATA
");
          Thread.sleep(delay);
          send("Subject: Email test
");
          Thread.sleep(delay);
          send("Test 1 2 3
");
          Thread.sleep(delay);
          send(".
");
          Thread.sleep(delay);
          send("QUIT
");
     }

     private static void send(String s) throws Exception
     {
          dos.writeBytes(s);
          System.out.println("CLIENT: "+s);
     }
}
Comment

PREVIOUS NEXT
Code Example
Java :: Uri/Beecrowd problem no 1180 solution in JAVA 
Java :: show all debug points intellij 
Java :: hippo get a node via id 
Java :: Removing Elements in java map 
Java :: java gson get object without class 
Java :: how to print an array in TImber android 
Java :: boolean parse jtextfield 
Java :: factorial function in java recursion 
Java :: create object of hashMap 
Java :: on offline event spigot example 
Java :: least count of words required to construct a target string 
Java :: intent for youtube android stackoveroverflow 
Java :: JSP Convertir Int a String 
Java :: unmappable character java 
Java :: JavaFX font display issue on Mac 
Java ::         System.out.println("Welcome to GeeksforGeeks"); 
Java :: android how to get position of a row in listview 
Java :: produces 
Java :: Reference in java equal operator 
Java :: java Generate parentheses all combinations 
Java :: Sample NavigableMap 
Java :: load list of integers from console 
Java :: could not find or load main class org.apache.catalina.startup.bootstrap caused by: java.lang.classnotfoundexception: org.apache.catalina.startup.bootstrap 
Java :: JAVA XML COURSE 
Java :: Java offer() 
Java :: how to write a java program for printing child or adult in java 
Java :: findbyname in jpa 
Java :: maximum occuring element in java 
Java :: generate infinity steam java 
Java :: java program finish event 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =