Skip to content

Commit 543995e

Browse files
Benny BottemaBenny Bottema
authored andcommitted
#218: Made Email serializable (except for attached/embedded DataSources, which is out of our control)
1 parent 820dcf9 commit 543995e

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

src/main/java/org/simplejavamail/email/AttachmentResource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import javax.annotation.Nonnull;
77
import javax.annotation.Nullable;
88
import java.io.IOException;
9+
import java.io.Serializable;
910
import java.nio.charset.Charset;
1011

1112
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -17,7 +18,7 @@
1718
*
1819
* @see DataSource
1920
*/
20-
public class AttachmentResource {
21+
public class AttachmentResource implements Serializable {
2122

2223
/**
2324
* @see #AttachmentResource(String, DataSource)

src/main/java/org/simplejavamail/email/Email.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javax.mail.internet.MimeMessage;
66
import java.io.File;
77
import java.io.InputStream;
8+
import java.io.Serializable;
89
import java.util.List;
910
import java.util.Map;
1011

@@ -17,7 +18,7 @@
1718
* Email message with all necessary data for an effective mailing action, including attachments etc. Exclusively created using {@link EmailBuilder}.
1819
*/
1920
@SuppressWarnings("SameParameterValue")
20-
public class Email {
21+
public class Email implements Serializable {
2122

2223
/**
2324
* @see EmailPopulatingBuilder#fixingMessageId(String)

src/main/java/org/simplejavamail/email/Recipient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import javax.annotation.Nonnull;
44
import javax.annotation.Nullable;
55
import javax.mail.Message.RecipientType;
6+
import java.io.Serializable;
67
import java.util.Objects;
78

89
import static org.simplejavamail.internal.util.Preconditions.checkNonEmptyArgument;
910

1011
/**
1112
* An immutable recipient object, with a name, emailaddress and recipient type (eg {@link RecipientType#BCC}).
1213
*/
13-
public final class Recipient {
14+
public final class Recipient implements Serializable {
1415

1516
@Nullable
1617
private final String name;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.simplejavamail.email;
2+
3+
import org.junit.Test;
4+
5+
import java.io.ByteArrayOutputStream;
6+
import java.io.IOException;
7+
import java.io.ObjectOutputStream;
8+
import java.io.OutputStream;
9+
10+
public class EmailTest {
11+
12+
@Test
13+
public void testSerialization() throws IOException {
14+
Email e = EmailBuilder.startingBlank()
15+
.from("lollypop", "[email protected]")
16+
.withReplyTo("lollypop-reply", "[email protected]")
17+
.withBounceTo("lollypop-bounce", "[email protected]")
18+
.to("C.Cane", "[email protected]")
19+
.withPlainText("We should meet up!")
20+
.withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>")
21+
.withSubject("hey")
22+
.withDispositionNotificationTo("[email protected]")
23+
.withReturnReceiptTo("Complex Email", "[email protected]")
24+
.withHeader("dummyHeader", "dummyHeaderValue")
25+
.buildEmail();
26+
27+
OutputStream fileOut = new ByteArrayOutputStream();
28+
ObjectOutputStream out = new ObjectOutputStream(fileOut);
29+
out.writeObject(e);
30+
out.close();
31+
fileOut.close();
32+
}
33+
}

0 commit comments

Comments
 (0)