Attachment without multipart

Hi,
Can anybody tell me if it is possible to send a mail with javamail without using MultiPart?
thanks

You are right! parsing of such not-multipart mail may look like that:
if (contentType.startsWith("application/xml")) {
            //just a plain attachement which is a mail's content and not a multipart.
            mimeParts = new String[1];
            //according to RFC 2822 empty line separates headers from the body
            mimeParts[0] = mimeMessage.substring(mimeMessage.indexOf("\n\r")).trim();
} else {
            //multipart mail
            javax.mail.util.ByteArrayDataSource ds = new javax.mail.util.ByteArrayDataSource(mimeMessage, "multipart/mixed");
            javax.mail.internet.MimeMultipart mm = new javax.mail.internet.MimeMultipart(ds);
            java.util.ArrayList<String> al = new java.util.ArrayList<String>();
            getAttachements(mm, al, 1);
            mimeParts = new String[0];
            mimeParts = al.toArray(mimeParts);
Thanks!

Similar Messages

  • Attachment without multipart content type

    Hello,
    My application receives mails sent from some different customers and parses the mail's attachments. The problem is that all these customers send their mails in a very different ways. Some of them send mails with "Content-Type: multipart/mixed;" header while some others send mail with the following headers (among some other):
    MIME-Version: 1.0
    Content-Type: application/xml
    Date: Tue, 11 Feb 2014 18:33:26 +0000
    From: <[email protected]>
    Message-ID: <1392143606.220.1@cls0361>
    Subject: orders000005311382.xml
    To: <[email protected]>
    There is no "Content-Type: multipart/mixed;" header at all. When I look at these messages with MS Outlook I can see that they have proper attachements.
    Now I have 2 problems:
    1. I would like to produce such an email myself since resending the received emails changes the message headers. There are lots of examples how to send a message with an attachment in Java with MimeMultipart object (this produces "Content-Type: multipart/mixed;") but I could not find one which sends the message with "Content-Type: application/xml" header only without any multipart header. I suspect that there are some specific applications which send mails in that way - not standard mail clients.
    2. I would like to get the attachment of a received mail with "Content-Type: application/xml" header. The following code works for "Content-Type: multipart/mixed;" only:
    public void invoke() throws Exception {
      /* Available Variables: DO NOT MODIFY
        In  : String mimeMessage
        In  : String encoding
        Out : String[] mimeParts
      * Available Variables: DO NOT MODIFY *****/
      javax.mail.util.ByteArrayDataSource ds = new javax.mail.util.ByteArrayDataSource(mimeMessage, "multipart/mixed");
      javax.mail.internet.MimeMultipart mm = new javax.mail.internet.MimeMultipart(ds);
      java.util.ArrayList<String> al = new java.util.ArrayList<String>();
      getAttachements(mm, al, 1);
      mimeParts = new String[0];
      mimeParts = al.toArray(mimeParts);
    private void getAttachements(javax.mail.internet.MimeMultipart mm, ArrayList<String> al, int depth) throws Exception {
      if (depth > 9) {
        return;
      int mimePartsCount = mm.getCount();
      for (int i = 0; i < mimePartsCount; i++){
        javax.mail.internet.MimeBodyPart mbp = (javax.mail.internet.MimeBodyPart)mm.getBodyPart(i);
        //System.out.println(depth + ": " + mbp + " " + mbp.getContentType() + " " + mbp.getContentID() + " " + mbp.getDisposition());
        if(mbp.getContentType().startsWith("multipart")){
          javax.mail.util.ByteArrayDataSource ds2 = new javax.mail.util.ByteArrayDataSource(mbp.getInputStream(), "multipart/mixed");
          javax.mail.internet.MimeMultipart mm2 = new javax.mail.internet.MimeMultipart(ds2);
          getAttachements(mm2, al, depth+1);
        } else {
          if (mbp.getDisposition() != null && mbp.getDisposition().startsWith("attachment") && !mbp.getContentType().contains("signature")){
            BufferedReader br = new BufferedReader(new InputStreamReader(mbp.getInputStream(),encoding));
            String s = br.readLine();
            StringBuffer sb = new StringBuffer();
            while (s != null) {
              sb.append(s);
              s = br.readLine();
            al.add(sb.toString());
    Could anyone suggest anything which may be helpful for resolving 1 or 2?
    Best regards

    You are right! parsing of such not-multipart mail may look like that:
    if (contentType.startsWith("application/xml")) {
                //just a plain attachement which is a mail's content and not a multipart.
                mimeParts = new String[1];
                //according to RFC 2822 empty line separates headers from the body
                mimeParts[0] = mimeMessage.substring(mimeMessage.indexOf("\n\r")).trim();
    } else {
                //multipart mail
                javax.mail.util.ByteArrayDataSource ds = new javax.mail.util.ByteArrayDataSource(mimeMessage, "multipart/mixed");
                javax.mail.internet.MimeMultipart mm = new javax.mail.internet.MimeMultipart(ds);
                java.util.ArrayList<String> al = new java.util.ArrayList<String>();
                getAttachements(mm, al, 1);
                mimeParts = new String[0];
                mimeParts = al.toArray(mimeParts);
    Thanks!

  • How can I print only the attachment without the email content

    How can I print only the attachment without the email content. Every time I send to print, It prints the email itself with the attachment- can I cancel that?

    Hello Riklama,
    When you first open the attachment (e.g. on your phone) than you can mail only that attachment. Works fine with my husbands blackberry.
    Elsy

  • Name of the Attachment without getting the entire message

    Hi,
    Does anybody here knows how can i list all the messages with attachments and the name of the files attached without invoking getBodyPart()? I want to use POP3 as my mail getting protocol.
    Thank's in advance
    Ivan Koji Koga

    hi , suresh
    in gi_packing_list
    do like this,
    gi_packing_list-obj_descr = XXX_<date>_<Time> .
    for file name pass parameter in obj_descr.
    Regards,
    Arpit

  • How can I create a mail attachment without a file suffix?

    Hi,
    I'm trying to create anl attachment without a suffix.
    Here is my code:
                   TextPayload attAnlFile = msg.createTextPayload();
                   attAnlFile.setName("File");
                   attAnlFile.setContentType("");
                   attAnlFile.setText("Test");
                   msg.addAttachment(attAnlFile);
                   inputModuleData.setPrincipalData(msg);
    I get a file named "File.bin", but i need a file, which is only named "File".
    Can anyone help me?
    Thanks a lot
    BR
    Ralf

    Hi Ralf,
    Ref: Receiver Mail Adapter
    The attachements are given a .bin extension by default. To change this , the procedure is available in the Mail Adapter FAQ : 856599
    Q: Can I choose the name of an attachment in the mail?
    A: Yes. Most mail clients use some heuristics based on some MIME headers to derive the name of an attachment. The MIME headers involved in most heuristics are Content-Type, Content-Description, and Content-Disposition. When you create an XI message, the XI payload name is automatically set in the Content-Description. If you want to change or set all of these headers, you can use the MessageTransformBean module (Note 793922) in the adapter framework.
    Related questions: How can I set the file name of a mail attachment?
    Q: How can I set the file name of a mail attachment?
    There are several MIME headers that play a role in how the client retrieves the file name of an attachment. Unfortunately, this behavior differs among various mail clients. The reason for this inconsistent behavior comes from the fact that this mechanism has been extended incrementally. The old way is to use the name parameter in the Content-Type header as specified in RFC1341. For example, you can set the content type of an XML attachment as:
    Content-Type: application/xml; name="abc.xml"
    RFC1521 discourages the use of this name parameter in anticipation of the new header Content-Disposition, which is defined in RFC1806.
    With this Content-Disposition header, you can set the file name as:
    Content-Disposition: attachment; filename="abc.xml"
    Some clients may show the Content-Description value as the file name. The Content-Description header is typically used to associate some descriptive information to an attachment (RFC1341) as in
    Content-Description: my xml file
    To avoid potential interpretation problems, it is recommended to combine the use of these headers.
    Also, the same note contains all info you wnat on the options of the mail adapter. Take a look at it.
    Regards,
    Jai Shankar

  • How to send soap attachment without SAAJ

    I have to send XML or text file as an attachment in the web service, just like email attachment. Currently I am intercepting the SOAP message (sent from web service client) and then adding an attachment using SAAJ. Can we send an attachment without intercepting and SAAJ in netbeans just like how we send other data (with basic datatypes ) as parameters to the web service operation ?
    TIA.

    Soap is a protocol that runs over TCP (sockets.) You can build the entire soap message by hand if you want to.
    That said adding something is dependent on the fact that the other side will consume it.

  • How to send any text as soap attachment without SAAJ ?

    I have to send XML or text file as an attachment in the web service, just like email attachment. Currently I am intercepting the SOAP message (sent from web service client) and then adding an attachment using SAAJ. Can we send an attachment without intercepting and SAAJ in netbeans just like how we send other data (with basic datatypes ) as parameters to the web service operation ?
    TIA.

    Wrong forum where to ask such questions.
    Check this one link:
    http://www.unix.com/shell-programming-scripting/18370-sending-email-text-attachment-using-mailx.html?t=18370#post70254

  • How do get attachment without triggering flag chaging from unread to read?

    Hi all,
    In IMAP, is there anyway to get the attachment without flipping the flag from unread to read?
    here's my code:
    store = session.getStore(IMAP);
    store.connect("someHost", somePort, "someLoginName", "somePwd");
    folder = (IMAPFolder)store.getFolder(INBOX);
    folder.open(Folder.READ_WRITE);
    javax.mail.Message message = folder.getMessageByUID(someUID);          
    if (message.isMimeType("audio/wav")) {
        InputStream is = message.getInputStream();
             while (nBytesRead != -1) {
                nBytesRead = is.read(buffer); // read the attachment from stream
    ...here's the bodystructure of the email:
    comand:
    A6 FETCH 3 (BODYSTRUCTURE)
    response:
    * 3 FETCH (BODYSTRUCTURE ("AUDIO" "WAV" ("NAME" "AUDIO.WAV" "TYPE" "Unknown") NIL NIL "BASE64" 7874 NIL NIL NIL))
    command:
    A7 FETCH 3 (BODY[TEXT]<0.7874>)
    response:
    * 3 FETCH (FLAGS (\Seen VOICE) BODY[TEXT]<0> {7874}
    [binary data...]
    As you see, the server sets the message to Seen (which is read state). How do I not set the flag to Seen?
    Thanks.
    Grace

    Why not just set it back to Not Seen after you do that?

  • When I try to send file from Reader as email it is attached without .pdf extension

    Hello,
    When I try to send file from Reader as email it is attached without .pdf extension.
    What could be a cause of this problem?
    TIA.

    Hello I got more info about this strange scenario. This happens when our user want to send a pdf file embedded on www page. Web application uses this control to display pdf files: Winnovative PDF Viewer Controls for ASP.NET and Windows Forms
    It is strange that when I try on my computer I will get file name with pdf extension, but people in different location get it without .pdf extension. I have no idea what happened, and now I am not sure if it is problem with Reader.
    User reports that he uses Adobe Reader version 11.0.0

  • Display attachment without showing pop-up List (CL_GOS_ATTACHMENTLIST)

    G'day!
    I try to display an attachment to a FI-document but without go via Attachment List.
    That is I don't want the attachment list to pop-up.
    Via my coding below I do get hold of the information I want from the attachment list...
    but THEN I want to KILL the object Attachment List so that the pop-up never shows.
    Any Ideas??
    (DATA: lo_list TYPE REF TO CL_GOS_ATTACHMENT_LIST.)
    *Get all attachment för object
    create object lo_list exporting is_object = ls_object .
    (DATA: lt_output TYPE TRL_BRLNK.)
    *Get the content of the attachmentlist...
    lt_output = lo_list->GO_LIST_VIEWER->gt_output.
    *Display all attachments.
    LOOP AT lt_output INTO ls_output.
      lo_bor_browser = ls_output-objref.
      create object go_display                            "(type ref to CL_SREL_LIST_BROWSER)
        exporting io_extension = lo_bor_browser
        exceptions others = 1.
      CALL METHOD go_display->DIRECT_DISPLAY_OBJECT "own method...only change of  SAP standard DIRECT_DISPLAY
        EXPORTING io_object = lo_bor_browser.
    ENDLOOP.
    I do find the attachment I want to display - But HOW do I avoid to show pop-up Attachment List.
    Best regards
    Henrik
    I guess my problem lies in CL_GOS_ATTACHMENT_LIST method CONSTRUCTOR
    METHOD CONSTRUCTOR .
      gs_object = is_object.
      gp_bds = ip_check_bds.
      gp_arlnk = ip_check_archive.
      gp_relation = ip_relation.
      IF go_list_viewer IS INITIAL.
    * create browser
        CREATE OBJECT go_list_viewer  !!!!!!!!!!!!!!!!!!! Anyone know how to avoid the pop-up Attachment list??
          EXPORTING
            io_extension            = me
            ip_service              = 'VIEW_ATTA'
          EXCEPTIONS
            others                  = 3
        go_list_viewer->gs_variant-report = sy-repid.
        go_list_viewer->gs_variant-handle = 'GOSA'.
        go_list_viewer->gp_no_dblclick    = ip_no_dblclick.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
          RAISING execution_failed.
        ENDIF.
      ENDIF.
    *  IF gp_bds = 'X' OR gp_arlnk = 'X'.
    *    gt_supertypes = it_supertypes.
    *    CALL METHOD check_supertypes
    *      EXPORTING ip_objtype = is_object-objtype.
    *  ENDIF.
      call method check_more_objects.
    * set the title of the browser
      CALL METHOD go_list_viewer->set_title
        EXPORTING ip_title = ip_title.
    * display attachment list                                           !!!!!!!!!!!!!!!!!!! Anyone know how to avoid the pop-up Attachment list??
      CALL METHOD go_list_viewer->new_display
        EXPORTING is_object    = is_object
                  ip_role      = 'APPLOBJ'
                  ip_relation  = ip_relation
                  ip_no_browse = 'X'
                  io_container = io_container.
    ENDMETHOD.
    Edited by: Henrik Andersson on Aug 20, 2009 10:46 AM

    ( I RECONSTRUCT THE MESSAGE)
    G'day!
    I try to display an attachment to a FI-document but without go via Attachment List.
    That is I don't want the attachment list to pop-up.
    Any Ideas??
    (DATA: lo_list TYPE REF TO CL_GOS_ATTACHMENT_LIST.)
    *Get all attachment för object
    create object lo_list exporting is_object = ls_object .
    (DATA: lt_output TYPE TRL_BRLNK.)
    *Get the content of the attachmentlist...
    lt_output = lo_list->GO_LIST_VIEWER->gt_output.
    *Display all attachments.
    LOOP AT lt_output INTO ls_output.
      lo_bor_browser = ls_output-objref.
      create object go_display                            "(type ref to CL_SREL_LIST_BROWSER)
        exporting io_extension = lo_bor_browser
        exceptions others = 1.
      CALL METHOD go_display->DIRECT_DISPLAY_OBJECT "own method...only change of  SAP standard DIRECT_DISPLAY
        EXPORTING io_object = lo_bor_browser.
    ENDLOOP.
    I do find the attachment I want to display - But HOW do I avoid to show pop-up Attachment List.
    I guess my problem lies in CL_GOS_ATTACHMENT_LIST method CONSTRUCTOR
    METHOD CONSTRUCTOR .
    But HOW do I avoid the POP-UP to be visible for customer.....
    I already have displayed the attachment....so the pop-up is not necessary. Less things for user to think about the better it is..
    There SAP use:
    CREATE OBJECT go_list_viewer 
          EXPORTING
            io_extension            = me
            ip_service              = 'VIEW_ATTA'
          EXCEPTIONS
            others                  = 3
    and
    * display attachment list         
      CALL METHOD go_list_viewer->new_display
        EXPORTING is_object    = is_object
                  ip_role      = 'APPLOBJ'
                  ip_relation  = ip_relation
                  ip_no_browse = 'X'
                  io_container = io_container.
    Best regards
    Henrik

  • How do I print Mail attachment without saving it first

    I'm new to Mavericks.  With Mail in Lion, I could scroll to the bottom of an email and double click on the icon for the Word doc or pdf attachment to open it, then hit command P to print it. With Mavericks, it appears that I have to first "save" the document somewhere and then open it and print it. Is this correct?
    In most cases, this is an extra step that is unnecessary.
    Right now, the attachment displays (opened) within the email, but I don't want to print several pages of an email when all I want is to print the attached doc, for instance, an attached invoice. Also, I can't tell what kind of document it is without saving it, which I don't like. I've tried to find a way around this in preferences but no luck.
    I guess what I'd really prefer is to go back to the old Lion version of Mail, or something that approximates it more closely. Do I need to just get over it and realize that I'm going to have to save every attachment if I want to print it or is there a workaround of some sort?

    Hi tbirdvet. Even though the content of the attachment now displays as part of the email message, I tried clicking on that portion of the email and, sure enough, the "attachment" popped up in Preview, just like you said. (I kept looking for a Word doc icon or a pdf icon to double click on, but they're no longer found at the bottom of the email or selectable from a drop down menu.)
    I'm so glad this worked. Thanks.

  • Receiver mail with text file attached without line feeds

    Hi, friends
    I have a text file  to mail scenario, where file must be attached to receiver mail.
    Receiver CC mail is protocol XIPAYLOAD and use mail package and keep attachment.
    In tab module, i have:
    Module name --> SAP XI Sample/ConvertCRLFfromToLF
    Module configuration --> mode LFtoCRLF
    The plain text file is attached to mail but there are no line feeds after the plain text lines.
    Thanks, in advance

    Stefan,
    This is not a Java mapping, it's an ABAP mapping.
    I've tryed also to insert this characters, but without success.
    In my abap class i have:
      data: l_newline type c value cl_abap_char_utilities=>newline.
      data: l_linefeed type c value cl_abap_char_utilities=>CR_LF.
      clear wa_string.
      incode = idocument->get_elements_by_tag_name( 'linea' ).
      length = incode->GET_LENGTH( ).
      do length times.
        outcode = incode->get_item( index = d_lines ).
        wa_linea = outcode->get_value( ).
        if wa_string is initial.
          wa_string = wa_linea.
        else.
          concatenate wa_string l_newline  l_linefeed crlf wa_linea into wa_string.
        endif.
        add 1 to d_lines.
      enddo.
      l_element_dummy  = l_document->create_simple_element(
                    name = 'Content'
                    VALUE = wa_string
                    parent = l_element_root  ).
    so...it's similar to your suggestion..
    Any other input, please?
    Regards,
    Carme.

  • How do I open mail attachment without having to save first

    I have an iMac with  Maverick 10.9.2 and  mail version 7.2. I am trying to switch over from my laptop to using the iMac exclusively. The laptop mail version is 4.6. In that version, when I receive an email with an attachment, there's a little icon of the attachment that I can just click on and open it. In the new version (7.2), there's no little icon. Instead, if i click on the attachment, it just shows a file name and I'm forced to choose to "save as" before I can open it. Is there a way to set up my preferences so i can see the icon and click to open without saving?
    Thanks!

    Open a message that contains attachments.
    Then hover your mouse over that line that separates the body of the message from the "To, From, Subject Line." On that line in the center, you are given a few options. Trash, Reply, Forward, and the attachments. Click on the attachments and down at the bottom of that list. You can select the "Quick Look". With the list, you can click on each attachment directly and given an option to download it.
    KOT

  • Cant re-send email with attach without waiting to upload?

    hi, thanks for the answer
    everytime i try re-sending an email with attach i cant press the send botton without waiting the loading time. So when i get some emails that i want to resend it takes me a lot of time.
    is there a way to re-send an email with attach pressing send without waiting the loading time so the email is program to send when the attach is loaded?

    No there is not a way, your phone needs to download the information first, before it can be sent as you need to tell it to do this before it sends, I would say try and connect to a wifi hot spot to get things faster dowloading and uploading.

  • Dynamic config for attachment without any message mapping in mail adapter

    Hi,
    In our scenario, we are not using any message mapping as a specification.A fixed length file is sent from source via proxy as an attachment to the mail.
    here the issue is with the file name of the attachment. how do we configure the attachment file name dynamically with out using any message maping.
    Regards,
    Divya

    Hi Divya,
    I understand you want to set name for mail attachment.
    SAP Note: Mail Adapter sapnote_0000856599
    Q: Can I choose the name of an attachment in the mail?
    A: Yes. Most mail clients use some heuristics based on some *MIME headers to derive the name of an attachment.* The MIME headers involved in most heuristics are Content-Type, Content-Description,and Content-Disposition. When you create an XI message, the XI payload name is automatically set in the Content-Description. If you want to change or set all of these headers, you can use the MessageTransformBean module (Note 793922) [Link|http://help.sap.com/saphelp_nwpi711/helpdata/en/57/0b2c4142aef623e10000000a155106/frameset.htm]
    in the adapter framework.
    Q: How can I set the file name of a mail attachment?
    There are several MIME headers that play a role in how the client retrieves the file name of an attachment. Unfortunately, this behavior differs among various mail clients. The reason for this inconsistent behavior comes from the fact that this mechanism has been extended incrementally. The old way is to use the name parameter in the Content-Type header as specified in RFC1341. For example, you can set the content type of an XML attachment as:
    Content-Type: application/xml; name="abc.xml"
    RFC1521 discourages the use of this name parameter in anticipation of the new header Content-Disposition, which is defined in RFC1806.
    With this Content-Disposition header, you can set the file name as:
    Content-Disposition: attachment; filename="abc.xml"
    Some clients may show the Content-Description value as the file name. The Content-Description header is typically used to associate some descriptive information to an attachment (RFC1341) as in
    Content-Description: my xml file
    To avoid potential interpretation problems, it is recommended to combine the use of these headers.
    Regards,
    Raghu_Vamsee
    Edited by: Raghu Vamsee on Feb 3, 2011 12:23 PM

Maybe you are looking for