Results 1 to 3 of 3
- 09-29-2011, 04:33 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 26
- Rep Power
- 0
Sending a data structure as an attachment via JavaMail
Hi, I've managed to send an email with a file as an attachment through JavaMail. However, I'd like to send a data structure (array, vector, etc.) as the attachment instead. One way of course is to export the data structure as a file and then attach that file, however that seems kind of redundant. Is there a way to directly parse the data structure as an attachment? My current partial code for sending an email with an attachment is
Java Code:public static void sendMail() throws Exception { String mailhost = "mailserver.asdasdasd.com"; String from = "fred_liu@asdasdas.com"; String sendTo[] = { "fred_liu@dfasfsdfs.com" }; String sendCC = ""; String subject = ""; String message = ""; String attachment = "C:\\fred.txt"; Properties prop = System.getProperties(); Session session = Session.getInstance(prop, null); Message msg = new MimeMessage(session); prop.put("mail.smtp.host", mailhost); msg.setFrom(new InternetAddress(from)); for (String to : sendTo) { msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); if (sendCC != null && sendCC.length() > 0) msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(sendCC, false)); msg.setSubject(subject); msg.setSentDate(Calendar.getInstance().getTime()); MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent(message, "text/html"); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); // Attachment messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(attachment); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(attachment); multipart.addBodyPart(messageBodyPart); msg.setContent(multipart); Transport.send(msg); } }
- 09-30-2011, 05:08 PM #2
Member
- Join Date
- Sep 2011
- Posts
- 26
- Rep Power
- 0
Re: Sending a data structure as an attachment via JavaMail
bump bumpbump bump
- 09-30-2011, 05:44 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
JavaMail - Problem while sending file attachment
By saniruddhabiswas in forum NetworkingReplies: 0Last Post: 06-13-2010, 11:16 AM -
Deleting an attachment after sending mail
By modestmj in forum Java ServletReplies: 2Last Post: 06-02-2010, 11:52 AM -
boundary, problem with sending several files as attachment
By anurit in forum Java AppletsReplies: 1Last Post: 03-05-2010, 02:05 AM -
Sending email with JavaMail
By eponcedeleon in forum Advanced JavaReplies: 2Last Post: 03-03-2010, 07:32 PM -
Sending MTOM Attachment through SOAP message
By suchismitasuchi in forum Advanced JavaReplies: 0Last Post: 01-19-2009, 01:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks