EmailAttachment attachment = new EmailAttachment(); String filePath = "pathtofile"; attachment.setPath(filePath); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("description for this attachment"); email.attach(attachment);
final URL url = attachment.getURL(); try fileName = attachment.getPath(); final File file = new File(fileName); if (!file.exists()) attach( new FileDataSource(file), attachment.getName(), attachment.getDescription(), attachment.getDisposition()); attach( url, attachment.getName(), attachment.getDescription(), attachment.getDisposition());
EmailAttachment attachment = new EmailAttachment(); attachment.setPath(filepath); attachment.setDisposition(EmailAttachment.ATTACHMENT); email.attach(attachment);
EmailAttachment attachment = new EmailAttachment(); attachment.setPath(attachmentPath); email.attach(attachment);
import org.apache.commons.mail.*; ... // Create the attachment EmailAttachment attachment = new EmailAttachment(); attachment.setPath("mypictures/john.jpg"); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Picture of John"); attachment.setName("John"); // Create the email message MultiPartEmail email = new MultiPartEmail(); email.setHostName("mail.myserver.com"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("The picture"); email.setMsg("Here is the picture you wanted"); // add the attachment email.attach(attachment); // send the email email.send();
@Test public void testGetSetDisposition() { for (final String validChar : testCharsValid) { attachment.setDisposition(validChar); assertEquals(validChar, attachment.getDisposition()); } }
@Test public void testGetSetDescription() { for (final String validChar : testCharsValid) { attachment.setDescription(validChar); assertEquals(validChar, attachment.getDescription()); } }
@Test public void testGetSetURL() throws Exception { final String[] tests = { "http://localhost/", "http://www.apache.org/", "http://foo.notexisting.org" }; for (final String urlString : tests) { final URL testURL = new URL(urlString); attachment.setURL(testURL); assertEquals(testURL, attachment.getURL()); } }
EmailAttachment attachment = new EmailAttachment(); attachment.setPath(pdfFile.getPath()); attachment.setDisposition(EmailAttachment.ATTACHMENT);
EmailAttachment attachment = new EmailAttachment(); attachment.setPath(attachmentPath); email.attach(attachment);
public static final String ATTACHMENT_PATH = "/opt/testfile/example_4mb_file.mp4"; // Create the attachment File attachFile = new File(ATTACHMENT_PATH); EmailAttachment attachment = new EmailAttachment(); attachment.setPath(attachFile.getAbsolutePath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachFile.getName()); attachment.setName(attachFile.getName()); // Create the email message MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator( EMAIL_USERNAME, EMAIL_PASSWORD)); email.setSSLOnConnect(true); email.addTo(EMAIL_RECEIVER); email.setFrom(EMAIL_SENDER, EMAIL_SUBJECT); email.setSubject("TestMail id " + this.uniqueId); email.setMsg("This is a test attachment mail ... :-)"); // add the attachment email.attach(attachment); // send the email email.send();
// Create the attachment EmailAttachment attachment = new EmailAttachment(); attachment.setPath(zipFile); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Zip File"); attachment.setName("myfiles.zip"); MultiPartEmail email = new MultiPartEmail(); email.attach(attachment);
EmailAttachment attachment = new EmailAttachment(); attachment.setPath(getAttachmentPath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); email.attach(attachment);
final URL url = attachment.getURL(); try fileName = attachment.getPath(); final File file = new File(fileName); if (!file.exists()) attach( new FileDataSource(file), attachment.getName(), attachment.getDescription(), attachment.getDisposition()); attach( url, attachment.getName(), attachment.getDescription(), attachment.getDisposition());
@Before public void setUpAttachmentTest() { attachment = new EmailAttachment(); }
private EmailAttachment makeAttachment(String att) { EmailAttachment r = new EmailAttachment(); r.setDisposition(EmailAttachment.ATTACHMENT); URL url = null; try { url = new URL(att); if (StringUtils.startsWithIgnoreCase(url.getProtocol(), "file")) { r.setPath(url.getPath()); } else { r.setURL(url); } } catch (MalformedURLException e) { r.setPath(att); } r.setName(FilenameUtils.getName(att)); return r; }
EmailAttachment attachment = new EmailAttachment(); attachment.setPath(getAttachmentPath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); email.attach(attachment);
email.attach(attachment); attachment = new EmailAttachment(); attachment.setPath("/Users/alkandari/Desktop/SMART/Fahim/test.png"); attachment.setDisposition(EmailAttachment.ATTACHMENT);