Skip to content

Commit dfac78f

Browse files
committed
/bbottema/simple-java-mail/issues/121: Added documentation on using a custom mailer
1 parent 499eae4 commit dfac78f

File tree

4 files changed

+80
-4
lines changed

4 files changed

+80
-4
lines changed

Diff for: dist/Features.html

+36-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ <h3>Builders all the way down</h3>
148148
<li><a href="#section-reply-forward">Replying to and forwarding emails</a></li>
149149
<li><a href="#section-proxy">Send using a proxy</a></li>
150150
<li><a href="#section-connection-test">Testing a server connection</a></li>
151-
<li><a href="#section-serializing-emails">Serializing Email objects</a></li>
151+
<li><a href="#section-serializing-emails">Serializing Email objects</a></li>
152+
<li><a href="#section-custom-mailer">Plug your own sending logic!</a></li>
152153
</ul>
153154
</section>
154155

@@ -1214,6 +1215,40 @@ <h2>Serializing Email objects</h2>
12141215
</ul>
12151216
</section>
12161217

1218+
1219+
<a href="#section-custom-mailer" id="section-custom-mailer" class="section-link h2">&sect;</a>
1220+
<h2>Plug your own sending logic!</h2>
1221+
1222+
<section>
1223+
<p class="wide">
1224+
You want to benefit from Simple Java Mail's powerful features, but want to replace the actual
1225+
server testing and email sending with your own? <br/>Simple Java Mail's got your back!
1226+
</p>
1227+
1228+
<hr/>
1229+
<div class="wide">
1230+
<p>Send mail using MailGun REST API:</p>
1231+
<pre><code>Mailer mailGunMailer = MailerBuilder
1232+
.(..)
1233+
.withCustomMailer(new MailGunMailer())
1234+
.buildMailer();
1235+
</code></pre>
1236+
<pre><code>public class MailGunMailer implements CustomMailer {
1237+
1238+
@Override
1239+
public void testConnection(OperationalConfig operationalConfig, Session session) {
1240+
// call MailGun rest service to test the provided config
1241+
}
1242+
1243+
@Override
1244+
public void sendMessage(OperationalConfig operationalConfig, Session session, Email email, MimeMessage message) {
1245+
// call MailGun rest service to send the email!
1246+
}
1247+
}
1248+
</code></pre>
1249+
</div>
1250+
</section>
1251+
12171252
</div>
12181253

12191254
</main>

Diff for: dist/configuration.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,11 @@ <h3>Programmatic API - other settings</h3>
399399
// this negates all related properties such as pool size and keepAliveTime
400400
currentMailerBuilder.withExecutorService(new MyAwesomeCustomThreadPoolExecutor())
401401
</code></pre>
402-
<pre><code class="small">// change the SMTP session timeout (affects socket connect-, read- and write timeouts)
402+
<pre><code class="small">// change the SMTP session timeout (affects socket connect-, read- and write timeouts)
403403
currentMailerBuilder.withSessionTimeout(10 * 1000); // 10 seconds for quick disconnect
404+
</code></pre>
405+
<pre><code class="small">// change the default sending logic to your own approach
406+
currentMailerBuilder.withCustomMailer(yourOwnMailSenderImpl); // send emails, test connections
404407
</code></pre>
405408
</div>
406409
</section>

Diff for: src/pages/Features.hbs

+36-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
<li><a href="#section-reply-forward">Replying to and forwarding emails</a></li>
9191
<li><a href="#section-proxy">Send using a proxy</a></li>
9292
<li><a href="#section-connection-test">Testing a server connection</a></li>
93-
<li><a href="#section-serializing-emails">Serializing Email objects</a></li>
93+
<li><a href="#section-serializing-emails">Serializing Email objects</a></li>
94+
<li><a href="#section-custom-mailer">Plug your own sending logic!</a></li>
9495
</ul>
9596
</section>
9697

@@ -1156,6 +1157,40 @@ mailer.testConnection(/* async? */); // no error means success
11561157
</ul>
11571158
</section>
11581159

1160+
1161+
<a href="#section-custom-mailer" id="section-custom-mailer" class="section-link h2">&sect;</a>
1162+
<h2>Plug your own sending logic!</h2>
1163+
1164+
<section>
1165+
<p class="wide">
1166+
You want to benefit from Simple Java Mail's powerful features, but want to replace the actual
1167+
server testing and email sending with your own? <br/>Simple Java Mail's got your back!
1168+
</p>
1169+
1170+
<hr/>
1171+
<div class="wide">
1172+
<p>Send mail using MailGun REST API:</p>
1173+
<pre><code>Mailer mailGunMailer = MailerBuilder
1174+
.(..)
1175+
.withCustomMailer(new MailGunMailer())
1176+
.buildMailer();
1177+
</code></pre>
1178+
<pre><code>public class MailGunMailer implements CustomMailer {
1179+
1180+
@Override
1181+
public void testConnection(OperationalConfig operationalConfig, Session session) {
1182+
// call MailGun rest service to test the provided config
1183+
}
1184+
1185+
@Override
1186+
public void sendMessage(OperationalConfig operationalConfig, Session session, Email email, MimeMessage message) {
1187+
// call MailGun rest service to send the email!
1188+
}
1189+
}
1190+
</code></pre>
1191+
</div>
1192+
</section>
1193+
11591194
</div>
11601195
{{/inline}}
11611196

Diff for: src/pages/configuration.hbs

+4-1
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,11 @@ currentMailerBuilder.withKeepAliveTime(5000);
341341
// this negates all related properties such as pool size and keepAliveTime
342342
currentMailerBuilder.withExecutorService(new MyAwesomeCustomThreadPoolExecutor())
343343
</code></pre>
344-
<pre><code class="small">// change the SMTP session timeout (affects socket connect-, read- and write timeouts)
344+
<pre><code class="small">// change the SMTP session timeout (affects socket connect-, read- and write timeouts)
345345
currentMailerBuilder.withSessionTimeout(10 * 1000); // 10 seconds for quick disconnect
346+
</code></pre>
347+
<pre><code class="small">// change the default sending logic to your own approach
348+
currentMailerBuilder.withCustomMailer(yourOwnMailSenderImpl); // send emails, test connections
346349
</code></pre>
347350
</div>
348351
</section>

0 commit comments

Comments
 (0)