use of com.outjected.email.impl.attachments.BaseAttachment in project simple-email by codylerum.
the class EmailMessage method addAttachment.
/**
* Adds an EmailAttachment to the EmailMessage
*
* @param attachment EmailAttachment to be added
*/
public void addAttachment(EmailAttachment attachment) {
BaseAttachment ba = new BaseAttachment(attachment.getFileName(), attachment.getMimeType(), attachment.getContentDisposition(), attachment.getBytes());
attachments.add(ba);
}
use of com.outjected.email.impl.attachments.BaseAttachment in project simple-email by codylerum.
the class MailContext method insert.
public String insert(String fileName) {
BaseAttachment attachment = null;
attachment = attachments.get(fileName);
if (attachment == null) {
throw new RuntimeException("Unable to find attachment: " + fileName);
} else {
return "cid:" + attachment.getContentId();
}
}
use of com.outjected.email.impl.attachments.BaseAttachment in project simple-email by codylerum.
the class MailMessageImpl method iCal.
@Override
public MailMessage iCal(String textBody, ICalMethod method, byte[] bytes) {
emailMessage.setType(EmailMessageType.INVITE_ICAL);
emailMessage.setTextBody(textBody);
emailMessage.addAttachment(new BaseAttachment(null, "text/calendar;method=" + method, ContentDisposition.INLINE, bytes, "urn:content-classes:calendarmessage"));
return this;
}
use of com.outjected.email.impl.attachments.BaseAttachment in project simple-email by codylerum.
the class XMLTests method simple.
@Test
public void simple() throws AddressException, JAXBException, IOException {
EmailMessage msg = new EmailMessage();
msg.setMessageId(UUID.randomUUID().toString() + "@test.org");
msg.setImportance(MessagePriority.HIGH);
msg.getFromAddresses().add(new InternetAddress("from@test.org", "Mr. From"));
msg.getToAddresses().add(new InternetAddress("to@test.org"));
msg.getCcAddresses().add(new InternetAddress("cc@test.org"));
msg.getBccAddresses().add(new InternetAddress("bcc@test.org"));
msg.setSubject("subject");
msg.setTextBody("text body");
msg.setHtmlBody("html body");
msg.addAttachment(new BaseAttachment("myfile.txt", "text/plain", ContentDisposition.ATTACHMENT, Resources.toByteArray(Resources.getResource("template.text.velocity"))));
msg.addAttachment(new BaseAttachment("myfile2.txt", "text/plain", ContentDisposition.ATTACHMENT, Resources.toByteArray(Resources.getResource("template.text.velocity"))));
msg.setEnvelopeFrom(new InternetAddress("env-from@test.org"));
msg.getReplyToAddresses().add(new InternetAddress("reply-to@test.org"));
msg.getHeaders().add(new Header("Sender", "sender@test.org"));
msg.getHeaders().add(new Header("X-Sender", "xsender@test.org"));
String xml = XMLUtil.marshal(msg);
EmailMessage umsg = XMLUtil.unmarshal(EmailMessage.class, xml);
Assert.assertTrue(msg.getType().equals(umsg.getType()));
Assert.assertTrue(msg.getCharset().equals(umsg.getCharset()));
Assert.assertTrue(msg.getImportance().equals(umsg.getImportance()));
Assert.assertTrue(msg.getToAddresses().get(0).equals(umsg.getToAddresses().get(0)));
Assert.assertTrue(msg.getFromAddresses().get(0).equals(umsg.getFromAddresses().get(0)));
Assert.assertTrue(msg.getCcAddresses().get(0).equals(umsg.getCcAddresses().get(0)));
Assert.assertTrue(msg.getBccAddresses().get(0).equals(umsg.getBccAddresses().get(0)));
Assert.assertTrue(msg.getSubject().equals(umsg.getSubject()));
Assert.assertTrue(msg.getTextBody().equals(umsg.getTextBody()));
Assert.assertTrue(msg.getHtmlBody().equals(umsg.getHtmlBody()));
Assert.assertTrue(msg.getMessageId().equals(umsg.getMessageId()));
Assert.assertTrue(msg.getAttachments().get(0).getFileName().equals(umsg.getAttachments().get(0).getFileName()));
}
Aggregations