comparison src/goodjava/mail/Examples.java @ 1585:c0ef8acf069d

multipart mail
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 12 Mar 2021 18:06:15 -0700
parents d3728e3e5af3
children fa1a9aceac3e
comparison
equal deleted inserted replaced
1584:d3728e3e5af3 1585:c0ef8acf069d
74 Smtp smtp = newSmtp(); 74 Smtp smtp = newSmtp();
75 smtp.send(msg); 75 smtp.send(msg);
76 smtp.close(); 76 smtp.close();
77 } 77 }
78 78
79 private static void multi() throws IOException, MailException {
80 Message msg1;
81 {
82 String text = ""
83 +"testing 1\n"
84 +"more\n"
85 ;
86 Map<String,String> headers = new LinkedHashMap<String,String>();
87 headers.put("Content-Type","text/plain; charset=utf-8");
88 msg1 = new Message(headers,text);
89 }
90
91 Message msg2;
92 {
93 String text = ""
94 +"testing 2\n"
95 +"more\n"
96 ;
97 Map<String,String> headers = new LinkedHashMap<String,String>();
98 headers.put("Content-Type","text/plain; charset=utf-8");
99 headers.put("Content-Disposition","attachment; filename=\"t2.txt\"");
100 msg2 = new Message(headers,text);
101 }
102
103 Message msg3;
104 {
105 byte[] flag = flag();
106 Map<String,String> headers = new LinkedHashMap<String,String>();
107 headers.put("Content-Type","image/png; name=\"flag.png\"");
108 // headers.put("Content-Type","image/png");
109 // headers.put("Content-Disposition","inline");
110 // headers.put("Content-Disposition","attachment; filename=\"flag.png\"");
111 msg3 = new Message(headers,flag);
112 }
113
114 Map<String,String> headers = new LinkedHashMap<String,String>();
115 headers.put("From","smtp@luan.software");
116 headers.put("To","fschmidt@gmail.com");
117 headers.put("Subject","multi");
118 headers.put("Content-Type","multipart/mixed");
119 Message[] content = new Message[]{msg1,msg2,msg3};
120 Message msg = new Message(headers,content);
121 Smtp smtp = newSmtp();
122 smtp.send(msg);
123 smtp.close();
124 }
125
79 public static void main(String[] args) throws Exception { 126 public static void main(String[] args) throws Exception {
80 mailText(); 127 multi();
81 } 128 }
82 } 129 }