Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

javamail and attachments

Options
  • 01-02-2005 2: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 Posts: 2,426 ✭✭✭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