public void testSendPDWithJavamail() { String host = ""; 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("", 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");
// Part two is attachment
MimeBodyPart attachmentMessageBodyPart = new MimeBodyPart();
byte[] pdf = new Resource("A1U0E0.pdf").getRawContent();
attachmentMessageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(pdf, "application/pdf")));
// Put parts in message
// Send the message
} catch (MessagingException e) {;
} catch (IOException e) {;
System.out.println("sent msg");

You might like also

How to insert a java applet in a web page
  I did learn a lot today while trying to validating my new sub domain: I found a huge number of examples using the tag <applet> which has been deprecated and create errors and warning in W3C validation engine. But no example using the  the new HTML <object> tag.  Hence I decide to publish this small post. The following page are now XHTM 1.0 display.php (validation Link) XHTML 1.0 Strict menu.html (validation link) XHTML 1.0 Transitional While this one …
3913 Days ago