Gel vatandas gell.. TikLaa'da gel..
Posts tagged java emailsender
Java ile Emailsender (Socket)
Ara 9th
Selam arkadaşlar, java ile basit bir emailsender yapmıştım paylaşmak istedim. Email hesabınızdan giriş yaptığınızda bu program üzerinden maillerinizi gönderebilirsiniz. Program statik çalışıyor, yani ne cmd’den nede herhangi bir arayüz aracılığı ile değişkenlere değer atanmıyor. Fakat bunu isterseniz çok basit bir şekilde yapabilirsiniz. Umarım işinize yarar.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import java.io.*; import java.net.*; public class EmailSender { public static void main(String[] args) throws Exception { Socket socket = new Socket("smtp.web.de",25); InputStream is = socket.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String response = br.readLine(); System.out.println(response); if (!response.startsWith("220")) { throw new Exception("220 reply not received from server."); } OutputStream os = socket.getOutputStream(); String command = "HELO localhost\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); response = br.readLine(); System.out.println(response); if (!response.startsWith("250")) { throw new Exception("250 reply not received from server."); } command = "MAIL FROM: qonyali@web.de\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); response = br.readLine(); System.out.println(response); if (!response.startsWith("250")) { throw new Exception("250 reply not received from server."); } command = "RCPT TO: halil@tiklaa.com\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); response = br.readLine(); System.out.println(response); if (!response.startsWith("250")) { throw new Exception("250 reply not received from server."); } command = "DATA\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); response = br.readLine(); System.out.println(response); if (!response.startsWith("354")) { throw new Exception("354 reply not received from server."); } command = "SUBJECT: Email Basligi\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); command = "E-Mail'in icerigi\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); command = ".\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); command = "QUIT\r\n"; System.out.print(command); os.write(command.getBytes("US-ASCII")); response = br.readLine(); System.out.println(response); if (!response.startsWith("250")) { throw new Exception("250 reply not received from server."); } } } |