/
FileEmailAttachment.java
44 lines (36 loc) · 1.16 KB
/
FileEmailAttachment.java
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
package org.jboss.seam.mail.core;
import java.io.File;
import java.io.IOException;
import javax.activation.FileDataSource;
import org.jboss.seam.mail.attachments.BaseAttachment;
import org.jboss.seam.mail.core.enumurations.ContentDisposition;
import com.google.common.io.Files;
/**
*
* @author Cody Lerum
*
*/
public class FileEmailAttachment extends BaseAttachment
{
public FileEmailAttachment(File file, ContentDisposition contentDisposition)
{
super();
FileDataSource fds = new FileDataSource(file);
try
{
super.setFileName(fds.getName());
super.setMimeType(fds.getContentType());
super.setContentDisposition(contentDisposition);
super.setBytes(Files.toByteArray(file));
}
catch (IOException e)
{
throw new AttachmentException("Wasn't able to create email attachment from File: " + file.getName(), e);
}
}
public FileEmailAttachment(File file, ContentDisposition contentDisposition, String contentClass)
{
this(file, contentDisposition);
super.addHeader(new Header("Content-Class", contentClass));
}
}