Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

javamail and attachments

  • 01-02-2005 02:04PM
    #1
    Closed Accounts Posts: 658 ✭✭✭


    Hi

    Im having a little problem re: Javamail and sending attachments. I know how to send an attachment when the source of the data is a file on the local filesystem, but how do I go about making an attachment if I want the file to be dynacmically created in memory instead and send to the use then ?

    I have a method to create the file in temporary memory using a ByteArrayOutputStream(), so can anyone help me with how to attach this to the email ? I have looked on the net and the tutorials only seem to deal with handling attachments from files.

    I know of FileDataSource and URLDataSource, but they arent much help.

    Thanks in advance :)


Comments

  • Registered Users, Registered Users 2, Paid Member Posts: 2,427 ✭✭✭ressem


    Nope you create/get a different datasource.

    Take your usual "create mail" example

    http://www.jguru.com/faq/view.jsp?EID=30251

    but instead of
    DataSource source = new FileDataSource(fileAttachment);

    use
    DataSource source = new ByteArrayDataSource(byte[] data, String type);

    as provided in your javamail/demo folder under ByteArrayDataSource.java, or by a few other vendors.
    [Added]
    like org.apache.commons.mail.ByteArrayDataSource
    at http://jakarta.apache.org/commons/


  • Closed Accounts Posts: 658 ✭✭✭pontovic


    thank you

    much obliged


Advertisement