Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

convenience constructors added to MandrillRecipient & MandrillAttachment #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0</version>
</dependency>


<dependency>
Expand All @@ -73,12 +78,6 @@
<version>1.8.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>


</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.cribbstechnologies.clients.mandrill.model;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;

public class MandrillAttachment {

String type;
Expand All @@ -12,6 +20,28 @@ public MandrillAttachment(String type, String name, String content) {
this.content = content;
}

public MandrillAttachment(File file, String type) {
this.name = file.getName();
this.type = type;
try {
FileInputStream is = new FileInputStream(file);
this.content = new String(Base64.encodeBase64(IOUtils.toByteArray(is)));
is.close();
} catch (IOException e) {
throw new RuntimeException("Can't encode attachment file " + file);
}
}

public MandrillAttachment(InputStream is, String fileName, String type) {
this.name = fileName;
this.type = type;
try {
this.content = new String(Base64.encodeBase64(IOUtils.toByteArray(is)));
} catch (IOException e) {
throw new RuntimeException("Can't encode attachment " + fileName);
}
}

public String getContent() {
return this.content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public class MandrillRecipient {
String name;
String type;

public MandrillRecipient(String email) {
this(email, email);
}

public MandrillRecipient(String name, String email) {
this.email = email;
this.name = name;
Expand Down