SHARE
TWEET

Untitled

a guest Nov 6th, 2018 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. package smtp;
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.io.PrintWriter;
  9. import java.net.InetAddress;
  10. import java.net.Socket;
  11. import java.net.UnknownHostException;
  12.  
  13. public class SMTPSkeleton {
  14.  
  15.     public static void main(String[] args) throws UnknownHostException, IOException {
  16.         String mailServer = "webmail.buet.ac.bd";
  17.         InetAddress mailHost = InetAddress.getByName(mailServer);
  18.         InetAddress localHost = InetAddress.getLocalHost();
  19.         Socket smtpSocket = new Socket(mailHost,25);
  20.         BufferedReader in =  new BufferedReader(new InputStreamReader(smtpSocket.getInputStream()));
  21.         PrintWriter pr = new PrintWriter(smtpSocket.getOutputStream(),true);
  22.         String initialID = in.readLine();
  23.         System.out.println(initialID);
  24.         pr.println("HELO "+mailHost.getHostName());
  25.         //System.out.println("HELO "+localHost.getHostName());
  26.         //pr.flush();
  27.         String welcome = in.readLine();
  28.         System.out.println(welcome);
  29.         pr.println("MAIL FROM:<sadamataalavi@gmail.com>");
  30.         //pr.flush();
  31.         String from = in.readLine();
  32.         System.out.println(from);
  33.         pr.println("RCPT TO:<ahnaffaisalalavi@gmail.com>");
  34.         //pr.flush();
  35.         String to = in.readLine();
  36.         System.out.println(to);
  37.         pr.println("RCPT TO:<turab2013@gmail.com>");
  38.         //pr.flush();
  39.         to = in.readLine();
  40.         System.out.println(to);
  41.         //pr.println("RCPT TO:<mustakimshovon69@gmail.com>");
  42.         //pr.flush();
  43.         //to = in.readLine();
  44.         System.out.println(to);
  45.         pr.println("DATA");
  46.         //pr.flush();
  47.         String res = in.readLine();
  48.         System.out.println(res);
  49.         //pr.println("DATA");
  50.        
  51.         pr.println("From: sadamataalavi@gmail.com");
  52.         pr.println("TO: ahnaffaisalalavi@gmail.com");
  53.        
  54.  
  55.  
  56.         pr.println("MIME-Version: 1.0");
  57.         pr.println("Subject: sample msg");
  58.         pr.println("Content-Type: multipart/mixed; boundary=\"simple boundary\"");
  59.         pr.println();
  60.        
  61.         pr.println("Greetings,");
  62.         pr.println("Hi");
  63.         pr.println("GoodBye.");
  64.         pr.println();
  65.        
  66.         //Content--Type: application/octet-stream; name=\"image.png\"
  67. //Content-Disposition: attachment; filename=\"image.png\"
  68. //Content-Transfer-Encoding: base64
  69.         pr.println("Content--Type: application/octet-stream; name=\"image.png\"");
  70.         pr.println("Content-Disposition: attachment; filename=\"image.png\"");
  71.         pr.println("Content-Transfer-Encoding: base64");
  72.         pr.println();
  73.        
  74.         pr.println(".");
  75.         res = in.readLine();
  76.         System.out.println(res);
  77.         pr.println("QUIT");
  78.         res = in.readLine();
  79.         System.out.println(res);
  80.         // TODO code application logic here
  81.     }
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top