-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmailReportSender.java
55 lines (51 loc) · 1.44 KB
/
EmailReportSender.java
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
import java.net.*;
import java.io.*;
public class EmailReportSender implements ScoreReportSender{
@Override
public void send(String recipient, String content) {
try {
Socket s = new Socket("osfmail.rit.edu", 25);
BufferedReader in =
new BufferedReader(
new InputStreamReader(s.getInputStream(), "8859_1"));
BufferedWriter out =
new BufferedWriter(
new OutputStreamWriter(s.getOutputStream(), "8859_1"));
// here you are supposed to send your username
sendln(in, out, "HELO world");
sendln(in, out, "MAIL FROM: <[email protected]>");
sendln(in, out, "RCPT TO: <" + recipient + ">");
sendln(in, out, "DATA");
sendln(out, "Subject: Bowling Score Report ");
sendln(out, "From: <Lucky Strikes Bowling Club>");
sendln(out, "Content-Type: text/plain; charset=\"us-ascii\"\r\n");
sendln(out, content + "\n\n");
sendln(out, "\r\n");
sendln(in, out, ".");
sendln(in, out, "QUIT");
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void sendln(BufferedReader in, BufferedWriter out, String s) {
try {
out.write(s + "\r\n");
out.flush();
// System.out.println(s);
s = in.readLine();
// System.out.println(s);
} catch (Exception e) {
e.printStackTrace();
}
}
public void sendln(BufferedWriter out, String s) {
try {
out.write(s + "\r\n");
out.flush();
System.out.println(s);
} catch (Exception e) {
e.printStackTrace();
}
}
}