How to add attachment to a mail from client side to an account

hi all,
i am using java mail api for my web-application. what i have done is that when the user submits a weekly-report form , the contents of form are mailed to a specific address acount in gmail from where i can retrieve all mails. i am able to achieve this.
what i want now is that the user should be able to attach some file to the report-form and that file comes as attachmernt to the gmail account.
How can i pass value to FileDataSource for filename as it looks for that in my local machine and not on client machine.
Please help and if u can give a sample code for reference also.
here is code snippet for jsp form and servlet for reference:-
jsp form code is:-
<FORM method="post" enctype="multipart/form-data" action="SendMailServlet">
<CENTER><TABLE BORDER=0 CELLPADDING=5 WIDTH="95%" >
<TR>
     <TD WIDTH="25%"><B>Name:</B></TD>     
     <TD WIDTH="25%"><INPUT type="text" name="name" size="20"></TD>
</tr>
<tr>
     <TD WIDTH="25%"><B>Comment: </B></TD>     
     <TD WIDTH="20%"><textarea cols="40" rows="4" name="comment"></textarea></TD>
</TR>
<tr>
     <TD WIDTH="25%"><B>Attachment: </B></TD>
     <TD WIDTH="20%"><INPUT type="file" name="file" size="20"></TD>
</TR>
corresponding code for servlet is:-
MimeBodyPart p1=new MimeBodyPart();
p1.setText( "FeedBack Sent From :- "+senderName+CR+
               "Comment Given is :- "+comment+CR);
//Set the attachments
MimeBodyPart p2=new MimeBodyPart();
FileDataSource fds=new FileDataSource(file);
p2.setDataHandler(new DataHandler(fds));
p2.setFileName(fds.getName());
Multipart mp=new MimeMultipart();
mp.addBodyPart(p1);
mp.addBodyPart(p2);
msg.setContent(mp);
msg.saveChanges();
Transport.send(msg);
Any help in this regard will be highly useful
thanks in advance
rahul

Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/list.html]How to Use Lists. It has an example of dynamically adding an item to the list. There is also a tutorial on "How to Use File Choosers" if thats your problem.
Start with the basics and read the tutorial.

Similar Messages

  • How can i load file into database from client-side to server-side

    i want to upload file from client-side to server-side, i use the following code to load blob into database.
    if the file is in the server-side, it can work, but if it in the client-side, it said that the system cannot find the file. i think it only will search the file is in the server-side or not, it will not search the client-side.
    how can i solve it without upload the file to the server first, then load it into database??
    try
    ResultSet rset = null;
    PreparedStatement pstmt =
    conn.prepareStatement ("insert into docs values (? , EMPTY_BLOB())");
    pstmt.setInt (1, docId);
    pstmt.execute ();
    // Open the destination blob:
    pstmt.setInt (1, docId);
    rset = pstmt.executeQuery (
    "SELECT content FROM docs WHERE id = ? FOR UPDATE");
    BLOB dest_lob = null;
    if (rset.next()) {
    dest_lob = ((OracleResultSet)rset).getBLOB (1);
    // Declare a file handler for the input file
    File binaryFile = new File (fileName);
    FileInputStream istream = new FileInputStream (binaryFile);
    // Create an OutputStram object to write the BLOB as a stream
    OutputStream ostream = dest_lob.getBinaryOutputStream();
    // Create a tempory buffer
    byte[] buffer = new byte[1024];
    int length = 0;
    // Use the read() method to read the file to the byte
    // array buffer, then use the write() method to write it to
    // the BLOB.
    while ((length = istream.read(buffer)) != -1)
    ostream.write(buffer, 0, length);
    pstmt.close();
    // Close all streams and file handles:
    istream.close();
    ostream.flush();
    ostream.close();
    //dest_lob.close();
    // Commit the transaction:
    conn.commit();
    conn.close();
    } catch (SQLException e) {

    Hi,
    Without some more details of the configuration, its difficult to know
    what's happening here. For example, what do you mean by client side
    and server side, and where are you running the upload Java application?
    If you always run the application on the database server system, but can't
    open the file on a different machine, then it sounds like a file protection
    problem that isn't really connected with the database at all. That is to
    say, if the new FileInputStream (binaryFile) statement fails, then its not
    really a database problem, but a file protection issue. On the other hand,
    I can't explain what's happening if you run the program on the same machine
    as the document file (client machine), but you can't write the data to the
    server, assuming the JDBC connection string is set correctly to connect to
    the appropriate database server.
    If you can provide some more information, we'll try to help.
    Simon
    null

  • How to add attachment to FI document from sap server

    Hi.SAP experts:
        I have files on SAP Server,and I want to attach these files to my FI Document,how could I achieve this goal without download the files into my local computer??
    Best Regards
    Martin Xie

    This could help you:
    http://www.whypad.com/posts/sap-attach-documents-to-a-journal-entry/45/

  • ADD ATTACHMENT TO AUTO MAIL SENT DURING BIDDER CREATION

    HOW TO ADD ATTACHMENT TO AUTO MAIL SENT DURING BIDDER CREATION (CREATE CONTACT PERSON) IN SRM PORTAL..

    HOW TO ADD ATTACHMENT TO AUTO MAIL SENT DURING BIDDER CREATION (CREATE CONTACT PERSON) IN SRM PORTAL..

  • Filename attachment in E-Mail from Support Message

    Hello,
    Can You explain me how to manage a filename of the attachment in E-Mail  from Solution manager ServiceDesk.
    We receive the mail notification with attachment which has always same filename - "service_operation.pdf".
    Thank you.

    Hi,
    Do you want to receive the e-mail as a pdf or e-mail? I suppose it is in a pdf. However, if you are unable to set teh attachment name, trying setting the e-mail in text format rather than pdf.
    You can check the SCOT setiing for SMTP> Internet>Set--> Output formats for SAP documents. Keep this value as TXT.
    This should help.
    Thanks,
    Rinkal

  • HT201320 How do I remove my e mail from sons I pad?

    How do I remove my e mail from sons I pad?

    I don't think it will delete from other devices. Make a note of the settings first, so if it does, you can add it back again on the device where you want it!! Although that's pretty much done automatically.
    I have an old iPad1 with multi-email accounts, but it's not iOS6.... on that you can select the account (in settings / email) and just switch off the accounts you don't want to pick up on that device.... not sure if you can do that in iOS6.
    As to giving your son his own Apple ID.... well, as a parent myself, I'm sure you'll want to share an account to save buying the same thing multiple times. We have about 10 computers/devices all sharing one account, and by playng with the settings on each one, we are not having too many issues.

  • How do I print an e mail from an I pad

    How do I print an e mail from an I pad

    The Print button (described in the Adobe Reader Help file) prints to AirPrint printers. Here's a list:
    A List of Printers with AirPrint (updated Nov. 2013)
    Otherwise, you can pay for an app like PrinterPro from Readdle if your printer is not AirPrint-enabled.

  • TS3899 How can i delete multiple e-mails from my iphone 4S. There are indicated more than 1500 e., but when i open the file there is indicated: no e-mail.

    How can i delete multiple e.mails from my iPhone 4 S. ? It shows the presence of more than 1500 e-mails. But when I try to open the account it shows that there a no e-mails. So i cannot delete them.

    I would disconnect the email on your phone...
    And reconnect again and if it still does that go on an actual computer, log on and delete the mails with ease...
    Hope this helps..it may just need to be refreshed...

  • How do we transfer contacts and mails from apple mail and address book to Microsoft outlook on my mac

    How do we transfer contacts and mails from apple mail and address book to Microsoft outlook on my mac

    From Contacts, anyway (the new version of Address Book) you can export to a .abbu file and import then into Outlook. I'm not sure about Mail as I only really use Outlook...
    Clinton

  • How to add screenshot to this thread from my hard drive?

    How to add screenshot to this thread from my hard drive?

    Unfortunately there is no built in way to do this. You would need to upload the picture some where and link to it in HTML.
    (Flickr, Picasa, Drop Box, etc.)

  • How do I stop all outgoing mail from being stored in my sent folder?

    How do I stop all outgoing mail from being stored in my sent folder?

    You cannot, but you can delete the mail in your Sent folder.

  • How do I move all my mail from Snow Leopard to Lion?

    How do I move all my mail from Snow Leopard to Lion?

    alphiza wrote:
    How do I move all my mail from Snow Leopard to Lion?
    Did you update over Snow Leopard or clean install. Have you got your latest backup of Snow Leopard?
    Pete

  • How can i erase my .me mails from my iPhone and keep them in the server

    how can i erase my .me mails from my iPhone and keep them in the server

    You can't. The iPhone doesn't actually store all your emails anyway. It is showing you what is on the server directly.
    Only the most recently accessed emails are cached (stored temporarily) on your phone for access when you are offline. If you delete an email from your iPhone, you are actually deleting it from the server.

  • How do I attach a 2nd PDF from iBook to the same email

    After I initiate an email from iBooks and attach a PDF document how do I attach a 2nd PDF from iBook to the same email

    You can only email one pdf at a time.

  • How do I sync my g-mail from my Mac OS X with my iphone?

    How do I sync my g-mail from my Mac OS X with my iphone? When I delete from my phone in g-mail I want the mail to be deleted from my Mac also. Can some-one help me with this. 

    You need to setup both of your email apps with imap.
    not sure if these are the greatest instructions ...
    https://support.google.com/mail/troubleshooter/1668960#ts=1665018,1665139
    Robert

Maybe you are looking for

  • Adding new authorization objects to transactions

    Hi experts, i would like to add new authorization objects to specific transactions, for example the object K_CCA for checking the cost element in the transaction KB15N. What do we have to maintain, except the transaction code with (SU22). What do we

  • Ipod disabled

    cant get into my son ipod says its disabled connect to itunes , how do i fix this problem as i dont know anything about ipods HELP NEEDED

  • Is there anyway I could get my FX and other effects to work on my Galaxy Tab 4?

    I try to do highlights/shadows  but it never seems to make any changes. Other effects don't work either. How could I fix this?

  • Is it possible to use the Internet User Alias?

    Hi, We are currently authenticating users against an LDAP datasource and pulling back the employee id as the SAP username in order to provide the correct authorisations. The problem with this is that we then have to create another user account for pe

  • Change of configuration Directory programmatic ...

    Hello, we are searching for a way to change the TestStand configuration Directory programmatically ... Before a sequence will be loaded... (maybe within the sequence file callback - SequenceFileLoad - if possible) (Menue: Configure>Station Options>Pr