Recommended sites

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits
Send created pdf with javamail Print E-mail
User Rating: / 0
PoorBest 
Sunday, 30 September 2007 12:16
public void testSendPDWithJavamail() {
String host = "mailhost.xxxxx.com";
String from = "
 This e-mail address is being protected from spambots, you need JavaScript enabled to view it
 ";
String to = "
 This e-mail 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");
}
Comments
Add New Search RSS
Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:):grin;)8):p:roll:eek:upset:zzz:sigh:?:cry
:(:x
Please input the anti-spam code that you can read in the image.

3.20 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Sunday, 30 September 2007 13:19 )
 
Content View Hits : 2416971

Enter Amount: