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);
|
|
15 Smtp smtp = new Smtp(socket);
|
|
16 smtp.authenticate("smtp@luan.software","luanhost");
|
|
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 +"产品\n" // some random chinese
|
|
39 +"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"
|
|
40 ;
|
|
41 Map<String,String> headers = new LinkedHashMap<String,String>();
|
|
42 headers.put("From","smtp@luan.software");
|
|
43 headers.put("To","fschmidt@gmail.com");
|
|
44 headers.put("Subject","test text");
|
|
45 headers.put("Content-Type","text/plain; charset=utf-8");
|
|
46 Message msg = new Message(headers,text);
|
|
47 Smtp smtp = newSmtp();
|
|
48 smtp.send(msg);
|
|
49 smtp.close();
|
|
50 }
|
|
51
|
|
52 private static byte[] flag() throws IOException {
|
|
53 URL url = new URL("https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Confederate_Rebel_Flag.svg/440px-Confederate_Rebel_Flag.svg.png");
|
|
54 InputStream in = url.openConnection().getInputStream();
|
|
55 byte[] a = new byte[100000];
|
|
56 int n = 0;
|
|
57 int i;
|
|
58 while( (i=in.read(a,n,a.length-n)) != -1 )
|
|
59 n += i;
|
|
60 in.close();
|
|
61 byte[] rtn = new byte[n];
|
|
62 System.arraycopy(a,0,rtn,0,n);
|
|
63 return rtn;
|
|
64 }
|
|
65
|
|
66 private static void mailFlag() throws IOException, MailException {
|
|
67 byte[] flag = flag();
|
|
68 Map<String,String> headers = new LinkedHashMap<String,String>();
|
|
69 headers.put("From","smtp@luan.software");
|
|
70 headers.put("To","fschmidt@gmail.com");
|
|
71 headers.put("Subject","test flag");
|
|
72 headers.put("Content-Type","image/png; name=\"flag.png\"");
|
|
73 Message msg = new Message(headers,flag);
|
|
74 Smtp smtp = newSmtp();
|
|
75 smtp.send(msg);
|
|
76 smtp.close();
|
|
77 }
|
|
78
|
|
79 public static void main(String[] args) throws Exception {
|
|
80 mailText();
|
|
81 }
|
|
82 }
|