public void testSendPDWithJavamail() {
String host = "mailhost.xxxxx.com";
String from = "
This email address is being protected from spambots. You need JavaScript enabled to view it.
";
String to = "
This email address is being protected from spambots. You need JavaScript enabled to view it.
";
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session
Session session = Session.getInstance(props, null);
try {
// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Hello JavaMail Attachment subject");
Multipart multipart = new MimeMultipart();
// Part one is a text
MimeBodyPart textMessageBodyPart = new MimeBodyPart();
textMessageBodyPart.setText("Hi hello this is the msg in mail");
multipart.addBodyPart(textMessageBodyPart);
// Part two is attachment
MimeBodyPart attachmentMessageBodyPart = new MimeBodyPart();
byte[] pdf = new Resource("A1U0E0.pdf").getRawContent();
attachmentMessageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(pdf, "application/pdf")));
multipart.addBodyPart(attachmentMessageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send(message);
} catch (MessagingException e) {
Assert.fail(e.getMessage());
} catch (IOException e) {
Assert.fail(e.getMessage());
}
System.out.println("sent msg");
}
Privacy Statement | Copyright Notice | Licenses
© 1999-2012 Waltercedric.com. Designed by Cédric Walter. Sitemap
Reproduction without explicit permission is prohibited. All Rights Reserved. All photos remain copyright © their rightful owners. No copyright infringement is intended.
Disclaimer: The editor(s) reserve the right to edit any comments that are found to be abusive, offensive, contain profanity, serves as spam, is largely self-promotional, or displaying attempts to harbour irrelevant text links for any purpose.