forked from bbottema/simple-java-mail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailTypesDemoApp.java
More file actions
205 lines (192 loc) · 8.47 KB
/
Copy pathEmailTypesDemoApp.java
File metadata and controls
205 lines (192 loc) · 8.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package demo;
import org.simplejavamail.email.EmailBuilder;
import javax.mail.util.ByteArrayDataSource;
import java.io.IOException;
/**
* Demonstration program for the Simple Java Mail framework. Just fill your gmail, password and press GO.
*/
@SuppressWarnings({"WeakerAccess", "UnusedAssignment"})
public class EmailTypesDemoApp extends DemoAppBase {
public static void main(final String[] args) throws IOException {
testSimplePlainText();
testSimpleHTMLText();
testMixed();
testRelated();
testAlternative();
testMixedRelated();
testMixedAlternative();
testRelatedAlternative();
testMixedRelatedAlternative();
}
private static void testSimplePlainText() {
mailerTLS.sendMail(EmailBuilder.startingBlank()
.to(YOUR_GMAIL_ADDRESS)
.withSubject("Demo email - simple (using plain text)")
.withPlainText("This is a simple email, the source contains no \"mixed\", \"related\" or \"alternative\" content.\n" +
"\n" +
"The root content is plain simple text.\n" +
"\n" +
"Formal structure:\n" +
"- plain text (root)")
.clearHTMLText()
.buildEmail());
}
private static void testSimpleHTMLText() {
mailerTLS.sendMail(EmailBuilder.startingBlank()
.to(YOUR_GMAIL_ADDRESS)
.withSubject("Demo email - simple (using HTML text)")
.withHTMLText("<p>This is a simple email, the source contains no \"mixed\", \"related\" or \"alternative\" content.</p>" +
"<p><i>The root content is <b>HTML</b> text.</i></p>" +
"<p><b>Formal structure:</b><br>" +
"<ul>" +
" <li>HTML text (root)</li>" +
"</ul></p>")
.clearPlainText()
.buildEmail());
}
private static void testMixed() throws IOException {
mailerTLS.sendMail(EmailBuilder.startingBlank()
.to(YOUR_GMAIL_ADDRESS)
.withSubject("Demo email - mixed")
.withPlainText("This is an email with \"mixed\" content: it contains a content part (this plain text) and an attachment\n" +
"\n" +
"Formal structure:\n" +
"-mixed (root)\n" +
" - plain text\n" +
" - attachment")
.withAttachment("dresscode.txt", new ByteArrayDataSource("Black Tie Optional", "text/plain")) // makes it mixed
.buildEmail());
}
private static void testRelated() {
// makes it related
mailerTLS.sendMail(EmailBuilder.startingBlank()
.to(YOUR_GMAIL_ADDRESS)
.withSubject("Demo email - related")
.withHTMLText("<p>This is an email with \"related\" content: it contains a content part (this HTML text) which references a " +
"related content part (the embedded image).</p><img src='cid:thumbsup'>" +
"<p><b>Formal structure:</b><br>" +
"<ul>" +
" <li>related (root)<ul>" +
" <li>HTML text</li>" +
" <li>embeddable image (cid:thumbsup) </li>" +
" </ul></li>" +
"</ul></p>")
.withEmbeddedImage("thumbsup", produceThumbsUpImage(), "image/png") // makes it related
.clearPlainText()
.buildEmail());
}
private static void testAlternative() {
mailerTLS.sendMail(EmailBuilder.startingBlank()
.to(YOUR_GMAIL_ADDRESS)
.withSubject("Demo email - alternative")
.withPlainText("plain text body here which should be ignored by any modern mail client")
.withHTMLText("<p>This is an email with \"alternative\" content: it contains a plain text content part (ignored in favor " +
"of HTML by modern mail clients) and a HTML content part (this HTML text)." +
"<p><b>Formal structure:</b><br>" +
"<ul>" +
" <li>alternative (root)<ul>" +
" <li>Plain text</li>" +
" <li>HTML text</li>" +
" </ul></li>" +
"</ul></p>") // makes it alternative
.buildEmail());
}
private static void testMixedRelated() throws IOException {
mailerTLS.sendMail(EmailBuilder.startingBlank()
.to(YOUR_GMAIL_ADDRESS)
.withSubject("Demo email - mixed + related")
.withHTMLText("<p>This is an email with \"mixed\" and \"related\" content: it contains a content part (this HTML text) which references a " +
"related content part (the embedded image) and contains an attachment as well.</p><img src='cid:thumbsup'>" +
"<p><b>Formal structure:</b><br>" +
"<ul>" +
" <li>mixed (root)<ul>" +
" <li>related<ul>" +
" <li>HTML text</li>" +
" <li>embeddable image (cid:thumbsup) </li>" +
" </ul></li>" +
" <li>attachment</li>" +
" </ul></li>" +
"</ul></p>")
.withAttachment("dresscode.txt", new ByteArrayDataSource("Black Tie Optional", "text/plain")) // makes it mixed
.withEmbeddedImage("thumbsup", produceThumbsUpImage(), "image/png") // makes it related
.clearPlainText()
.buildEmail());
}
private static void testMixedAlternative() throws IOException {
mailerTLS.sendMail(EmailBuilder.startingBlank()
.to(YOUR_GMAIL_ADDRESS)
.withSubject("Demo email - mixed + alternative")
.withPlainText("plain text body here which should be ignored by any modern mail client")
.withAttachment("dresscode.txt", new ByteArrayDataSource("Black Tie Optional", "text/plain")) // makes it mixed
.withHTMLText("<p>This is an email with \"mixed\" and \"alternative\" content: it contains a plain text content part " +
"(ignored in favor of HTML by modern mail clients) and a HTML content part (this HTML text) and contains an " +
"attachment as well.</p>" +
"<p><b>Formal structure:</b><br>" +
"<ul>" +
" <li>mixed (root)<ul>" +
" <li>alternative<ul>" +
" <li>Plain text</li>" +
" <li>HTML text</li>" +
" </ul></li>" +
" <li>attachment</li>" +
" </ul></li>" +
"</ul></p>") // makes it alternative
.buildEmail());
}
private static void testRelatedAlternative() {
mailerTLS.sendMail(EmailBuilder.startingBlank()
.to(YOUR_GMAIL_ADDRESS)
.withSubject("Demo email - related + alternative")
.withPlainText("plain text body here which should be ignored by any modern mail client")
.withEmbeddedImage("thumbsup", produceThumbsUpImage(), "image/png") // makes it related
.withHTMLText("<p>This is an email with \"related\" and \"alternative\" content: it contains a plain text part (ignored in " +
"favor of HTML by modern clients) and an HTML content part (this HTML text) which references a " +
"related content part (the embedded image).</p><img src='cid:thumbsup'>" +
"<p><b>Formal structure:</b><br>" +
"<ul>" +
" <li>related (root)<ul>" +
" <li>alternative<ul>" +
" <li>Plain text</li>" +
" <li>HTML text</li>" +
" </ul></li>" +
" <li>embeddable image (cid:thumbsup)</li>" +
" </ul></li>" +
"</ul></p>") // makes it alternative
.buildEmail());
}
private static void testMixedRelatedAlternative() throws IOException {
mailerTLS.sendMail(EmailBuilder.startingBlank()
.to(YOUR_GMAIL_ADDRESS)
.withSubject("Demo email - mixed + related + alternative")
.withPlainText("plain text body here which should be ignored by any modern mail client")
.withAttachment("dresscode.txt", new ByteArrayDataSource("Black Tie Optional", "text/plain")) // makes it mixed
.withEmbeddedImage("thumbsup", produceThumbsUpImage(), "image/png") // makes it related
.withHTMLText("<p>This is an email with \"mixed\", \"related\" and \"alternative\" content: it contains a plain text part " +
"(ignored in favor of HTML by modern clients) and an HTML content part (this HTML text) which references a related " +
"content part (the embedded image). In addition this email contains a separate attachment as well.</p>" +
"<img src='cid:thumbsup'>" +
"<p><b>Formal structure:</b><br>" +
"<ul>" +
" <li>mixed (root)<ul>" +
" <li>related<ul>" +
" <li>alternative<ul>" +
" <li>plain text</li>" +
" <li>HTML text</li>" +
" </ul></li>" +
" <li>embeddable image (cid:thumbsup) </li>" +
" </ul></li>" +
" <li>attachment</li>" +
" </ul></li>" +
"</ul></p>") // makes it alternative
.buildEmail());
}
}