Skip to content

Commit

Permalink
#218: Made Email serializable (except for attached/embedded DataSourc…
Browse files Browse the repository at this point in the history
…es, which is out of our control)
  • Loading branch information
Benny Bottema authored and Benny Bottema committed Sep 27, 2019
1 parent 820dcf9 commit 543995e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.Charset;

import static java.nio.charset.StandardCharsets.UTF_8;
Expand All @@ -17,7 +18,7 @@
*
* @see DataSource
*/
public class AttachmentResource {
public class AttachmentResource implements Serializable {

/**
* @see #AttachmentResource(String, DataSource)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/simplejavamail/email/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.io.InputStream;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

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

/**
* @see EmailPopulatingBuilder#fixingMessageId(String)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/simplejavamail/email/Recipient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.mail.Message.RecipientType;
import java.io.Serializable;
import java.util.Objects;

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

/**
* An immutable recipient object, with a name, emailaddress and recipient type (eg {@link RecipientType#BCC}).
*/
public final class Recipient {
public final class Recipient implements Serializable {

@Nullable
private final String name;
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/org/simplejavamail/email/EmailTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.simplejavamail.email;

import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

public class EmailTest {

@Test
public void testSerialization() throws IOException {
Email e = EmailBuilder.startingBlank()
.from("lollypop", "[email protected]")
.withReplyTo("lollypop-reply", "[email protected]")
.withBounceTo("lollypop-bounce", "[email protected]")
.to("C.Cane", "[email protected]")
.withPlainText("We should meet up!")
.withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>")
.withSubject("hey")
.withDispositionNotificationTo("[email protected]")
.withReturnReceiptTo("Complex Email", "[email protected]")
.withHeader("dummyHeader", "dummyHeaderValue")
.buildEmail();

OutputStream fileOut = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(e);
out.close();
fileOut.close();
}
}

0 comments on commit 543995e

Please sign in to comment.