imported from svn
[metux-java.git] / util / SendMail.java
blob7ede3f64279c9983df2b5e8c15a660d8c545cedb
2 package org.de.metux.util;
4 import java.awt.*;
5 import javax.swing.*;
7 public class SendMail
9 String from = "roboter@metux.de";
10 String to = "weigelt@metux.de";
11 String subject = "bummsfallera";
12 String body = "hello world";
14 public SendMail()
18 static public void main(String args[]) {
19 (new SendMail()).send();
22 java.io.BufferedReader _in;
23 java.io.PrintWriter _out;
25 protected void send(String s) throws java.io.IOException
27 // Send the SMTP command
28 if (s != null) {
29 System.out.println("C: "+s);
30 _out.println(s);
31 _out.flush();
33 // Wait for the response
34 String line = _in.readLine();
35 if (line != null) {
36 System.out.println("S:" + line);
40 void send()
42 try
44 java.net.Socket s = new java.net.Socket("nibiru.local", 25);
45 _out = new java.io.PrintWriter(s.getOutputStream());
46 _in = new java.io.BufferedReader(
47 new java.io.InputStreamReader(s.getInputStream()));
49 send(null);
50 send("HELO " + java.net.InetAddress.getLocalHost().getHostName());
51 send("MAIL FROM: " + from);
52 send("RCPT TO: " + to);
53 send("DATA");
54 _out.println("Subject:" + subject);
55 _out.println(body);
56 send(".");
57 s.close();
59 } catch (Exception e)
61 System.err.println("Error: " + e);