+ "To: jane@jane.net\r\n"
+ "Subject: Me Tarzan, you Jane\r\n"
+ "MIME-Version: 1.0\r\n"
- + "Content-Type: multipart/mixed; boundary=snip_snip\r\n"
+ + "Content-Type: multipart/mixed; boundary=\"snip_snip\"\r\n"
+ "\r\n"
+ "--snip_snip\r\n"
+ "Content-Type: text/plain\r\n"
+ "--snip_snip--\r\n"
+ "\r\n.\r\n"
+ "QUIT\r\n";
+ final String HTML =
+ "<HTML>\n"
+ + "<HEAD>\n"
+ + "<TITLE>Me Tarzan; you Jane\n</TITLE>"
+ + "</HEAD>\n"
+ + "<BODY>\n"
+ + "<P>Tarzan like Jane.<BR/>Tarzan come see Jane soon.</P>\n"
+ + "<P>Tarzan</P>\n"
+ + "</BODY>\n"
+ + "</HTML>";
+ final String HTML_SENT =
+ "MAIL FROM: tarzan@jane.net\r\n"
+ + "RCPT TO: jane@jane.net\r\n"
+ + "DATA\r\n"
+ + "From: tarzan@jane.net\r\n"
+ + "To: jane@jane.net\r\n"
+ + "Subject: Me Tarzan, you Jane\r\n"
+ + "MIME-Version: 1.0\r\n"
+ + "Content-Type: multipart/mixed; boundary=\"snip_snip\"\r\n"
+ + "\r\n"
+ + "--snip_snip\r\n"
+ + "Content-Type: text/html\r\n"
+ + "\r\n"
+ + HTML
+ + "\r\n\r\n--snip_snip--\r\n"
+ + "\r\n.\r\n"
+ + "QUIT\r\n";
- SmtpConversationMock conversat = new SmtpConversationMock(TYPICAL_INIT, TYPICAL);
- SendMailMock smm = new SendMailMock(conversat);
-
- smm.setFrom("tarzan@jane.net");
- smm.addTo("jane@jane.net");
- smm.setSubject("Me Tarzan, you Jane");
-
- MimePart part = new MimePart("text/plain", "Tarzan like Jane\nTarzan come see Jane soon\n\nTarzan");
- smm.addPart(part);
-
- smm.send();
-
- OutputStreamMock osm = conversat.getOutputStream();
- String result = osm.mock_getContent(Charset.forName(FileMock.UTF_8));
-
- int pos = result.indexOf("\r\n");
- assertTrue(pos > 0);
- String afterHELO = result.substring(pos + 2);
+ // Try sending a plain-text email
+ {
+ SmtpConversationMock conversat = new SmtpConversationMock(TYPICAL_INIT, TYPICAL);
+ SendMailMock smm = new SendMailMock(conversat);
+
+ smm.setFrom("tarzan@jane.net");
+ smm.addTo("jane@jane.net");
+ smm.setSubject("Me Tarzan, you Jane");
+
+ MimePart part = new MimePart("text/plain", "Tarzan like Jane\nTarzan come see Jane soon\n\nTarzan");
+ smm.addPart(part);
+
+ smm.send();
+
+ OutputStreamMock osm = conversat.getOutputStream();
+ String result = osm.mock_getContent(Charset.forName(FileMock.UTF_8));
+
+ int pos = result.indexOf("\r\n");
+ assertTrue(pos > 0);
+ String afterHELO = result.substring(pos + 2);
+
+ assertTrue(result.startsWith("HELO "));
+ assertEquals(TYPICAL_SENT, afterHELO);
+ }
- assertTrue(result.startsWith("HELO "));
- assertEquals(TYPICAL_SENT, afterHELO);
+ // Try sending an HTML email
+ {
+ SmtpConversationMock conversat = new SmtpConversationMock(TYPICAL_INIT, TYPICAL);
+ SendMailMock smm = new SendMailMock(conversat);
+
+ smm.setFrom("tarzan@jane.net");
+ smm.addTo("jane@jane.net");
+ smm.setSubject("Me Tarzan, you Jane");
+
+ MimePart part = new MimePart("text/html", HTML);
+ smm.addPart(part);
+
+ smm.send();
+
+ OutputStreamMock osm = conversat.getOutputStream();
+ String result = osm.mock_getContent(Charset.forName(FileMock.UTF_8));
+
+ int pos = result.indexOf("\r\n");
+ assertTrue(pos > 0);
+ String afterHELO = result.substring(pos + 2);
+
+ assertTrue(result.startsWith("HELO "));
+ assertEquals(HTML_SENT, afterHELO);
+ }
}
}