Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/src/goodjava/mail/Examples.java Thu Mar 11 01:22:20 2021 -0700 +++ b/src/goodjava/mail/Examples.java Fri Mar 12 18:06:15 2021 -0700 @@ -76,7 +76,54 @@ smtp.close(); } + private static void multi() throws IOException, MailException { + Message msg1; + { + String text = "" + +"testing 1\n" + +"more\n" + ; + Map<String,String> headers = new LinkedHashMap<String,String>(); + headers.put("Content-Type","text/plain; charset=utf-8"); + msg1 = new Message(headers,text); + } + + Message msg2; + { + String text = "" + +"testing 2\n" + +"more\n" + ; + Map<String,String> headers = new LinkedHashMap<String,String>(); + headers.put("Content-Type","text/plain; charset=utf-8"); + headers.put("Content-Disposition","attachment; filename=\"t2.txt\""); + msg2 = new Message(headers,text); + } + + Message msg3; + { + byte[] flag = flag(); + Map<String,String> headers = new LinkedHashMap<String,String>(); + headers.put("Content-Type","image/png; name=\"flag.png\""); +// headers.put("Content-Type","image/png"); +// headers.put("Content-Disposition","inline"); +// headers.put("Content-Disposition","attachment; filename=\"flag.png\""); + msg3 = new Message(headers,flag); + } + + Map<String,String> headers = new LinkedHashMap<String,String>(); + headers.put("From","smtp@luan.software"); + headers.put("To","fschmidt@gmail.com"); + headers.put("Subject","multi"); + headers.put("Content-Type","multipart/mixed"); + Message[] content = new Message[]{msg1,msg2,msg3}; + Message msg = new Message(headers,content); + Smtp smtp = newSmtp(); + smtp.send(msg); + smtp.close(); + } + public static void main(String[] args) throws Exception { - mailText(); + multi(); } }