1584
|
1 package goodjava.mail;
|
|
2
|
|
3 import java.io.InputStream;
|
|
4 import java.io.IOException;
|
|
5 import java.net.Socket;
|
|
6 import java.net.URL;
|
|
7 import java.util.Map;
|
|
8 import java.util.LinkedHashMap;
|
|
9
|
|
10
|
|
11 public class Examples {
|
|
12
|
|
13 private static Smtp newSmtp() throws IOException, MailException {
|
|
14 Socket socket = new Socket("smtpcorp.com",2525);
|
1830
|
15 Smtp smtp = new Smtp(socket);
|
1824
|
16 smtp.authenticate("luan","luanhost2");
|
1584
|
17 return smtp;
|
|
18 }
|
|
19
|
|
20 private static void smtp() throws IOException, MailException {
|
|
21 Smtp smtp = newSmtp();
|
|
22 smtp.from("smtp@luan.software");
|
|
23 smtp.to("fschmidt@gmail.com");
|
|
24 String text = "\r\n"
|
|
25 +"test3\r\n"
|
|
26 +".q\r\n"
|
|
27 +"x\r\n"
|
|
28 +"rg; ;lrg dsl rgj errlgerrg neskrjg skrg rdsg drskrg sd;gr s;kgr skrg skrg sdg ds fg;ks gegr erg ;sg sd; g;sdr gsklrg sg s;kkrg s;hg ;slrg ;elrg ;reg r;g ;r g;er g;ler g;e g; g;r g rg; srkd fjl kj kklsjrg lsk gskdf;rs gkrj glj grekjs lksjgkjn kjslg rklrg ;rsd; kj drsg akrglk kalrgklrsdnrgkgj;r ;s ns b;n;sn ;njslk r;n\r\n"
|
|
29 ;
|
|
30 smtp.data(text);
|
|
31 smtp.close();
|
|
32 }
|
|
33
|
|
34 private static void mailText() throws IOException, MailException {
|
|
35 String text = ""
|
|
36 +"testm 2\n"
|
|
37 +"x\n"
|
|
38 +"rg; ;lrg dsl rgj errlgerrg neskrjg skrg rdsg drskrg sd;gr s;kgr skrg skrg sdg ds fg;ks gegr erg ;sg sd; g;sdr gsklrg sg s;kkrg s;hg ;slrg ;elrg ;reg r;g ;r g;er g;ler g;e g; g;r g rg; srkd fjl kj kklsjrg lsk gskdf;rs gkrj glj grekjs lksjgkjn kjslg rklrg ;rsd; kj drsg akrglk kalrgklrsdnrgkgj;r ;s ns b;n;sn ;njslk r;n\n"
|
|
39 ;
|
|
40 Map<String,String> headers = new LinkedHashMap<String,String>();
|
|
41 headers.put("From","smtp@luan.software");
|
|
42 headers.put("To","fschmidt@gmail.com");
|
|
43 headers.put("Subject","test text");
|
1587
|
44 // headers.put("Content-Type","text/plain; charset=utf-8");
|
1584
|
45 Message msg = new Message(headers,text);
|
|
46 Smtp smtp = newSmtp();
|
|
47 smtp.send(msg);
|
|
48 smtp.close();
|
|
49 }
|
|
50
|
|
51 private static byte[] flag() throws IOException {
|
|
52 URL url = new URL("https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Confederate_Rebel_Flag.svg/440px-Confederate_Rebel_Flag.svg.png");
|
|
53 InputStream in = url.openConnection().getInputStream();
|
|
54 byte[] a = new byte[100000];
|
|
55 int n = 0;
|
|
56 int i;
|
|
57 while( (i=in.read(a,n,a.length-n)) != -1 )
|
|
58 n += i;
|
|
59 in.close();
|
|
60 byte[] rtn = new byte[n];
|
|
61 System.arraycopy(a,0,rtn,0,n);
|
|
62 return rtn;
|
|
63 }
|
|
64
|
|
65 private static void mailFlag() throws IOException, MailException {
|
|
66 byte[] flag = flag();
|
|
67 Map<String,String> headers = new LinkedHashMap<String,String>();
|
|
68 headers.put("From","smtp@luan.software");
|
|
69 headers.put("To","fschmidt@gmail.com");
|
|
70 headers.put("Subject","test flag");
|
|
71 headers.put("Content-Type","image/png; name=\"flag.png\"");
|
|
72 Message msg = new Message(headers,flag);
|
|
73 Smtp smtp = newSmtp();
|
|
74 smtp.send(msg);
|
|
75 smtp.close();
|
|
76 }
|
|
77
|
1585
|
78 private static void multi() throws IOException, MailException {
|
|
79 Message msg1;
|
|
80 {
|
|
81 String text = ""
|
|
82 +"testing 1\n"
|
|
83 +"more\n"
|
|
84 ;
|
|
85 Map<String,String> headers = new LinkedHashMap<String,String>();
|
|
86 headers.put("Content-Type","text/plain; charset=utf-8");
|
|
87 msg1 = new Message(headers,text);
|
|
88 }
|
|
89
|
|
90 Message msg2;
|
|
91 {
|
|
92 String text = ""
|
|
93 +"testing 2\n"
|
|
94 +"more\n"
|
|
95 ;
|
|
96 Map<String,String> headers = new LinkedHashMap<String,String>();
|
|
97 headers.put("Content-Type","text/plain; charset=utf-8");
|
|
98 headers.put("Content-Disposition","attachment; filename=\"t2.txt\"");
|
|
99 msg2 = new Message(headers,text);
|
|
100 }
|
|
101
|
|
102 Message msg3;
|
|
103 {
|
|
104 byte[] flag = flag();
|
|
105 Map<String,String> headers = new LinkedHashMap<String,String>();
|
|
106 headers.put("Content-Type","image/png; name=\"flag.png\"");
|
|
107 // headers.put("Content-Type","image/png");
|
|
108 // headers.put("Content-Disposition","inline");
|
|
109 // headers.put("Content-Disposition","attachment; filename=\"flag.png\"");
|
|
110 msg3 = new Message(headers,flag);
|
|
111 }
|
|
112
|
|
113 Map<String,String> headers = new LinkedHashMap<String,String>();
|
|
114 headers.put("From","smtp@luan.software");
|
|
115 headers.put("To","fschmidt@gmail.com");
|
|
116 headers.put("Subject","multi");
|
|
117 headers.put("Content-Type","multipart/mixed");
|
|
118 Message[] content = new Message[]{msg1,msg2,msg3};
|
|
119 Message msg = new Message(headers,content);
|
|
120 Smtp smtp = newSmtp();
|
|
121 smtp.send(msg);
|
|
122 smtp.close();
|
|
123 }
|
|
124
|
1584
|
125 public static void main(String[] args) throws Exception {
|
1587
|
126 mailText();
|
1584
|
127 }
|
|
128 }
|