How to upload a PDF-file and send it by SAP Mail

Hi,
we need to attach a pdf-file to an email send by SAP. The file is stored in a SAP-directory. When I use Open dataset to get the file it works but when sent by email the file could not be opened. I guess that perhaps I have to use other parameters to get the PDF in a correct file but I don't know which ones. Here is part of the coding I use for testing:
TYPES: BEGIN OF typ_pdf,
       line(255),
       END OF typ_pdf.
DATA: it_pdf TYPE STANDARD TABLE OF typ_pdf,
      wa_pdf LIKE LINE OF it_pdf.
v_file = '/pool//Test.pdf'.
OPEN DATASET v_file FOR INPUT IN TEXT MODE ENCODING NON-UNICODE.
WHILE ( sy-subrc EQ 0 ).
  READ DATASET v_file INTO wa_pdf.
  IF NOT wa_pdf IS INITIAL.
    APPEND wa_pdf TO it_pdf.
  ENDIF.
  CLEAR wa_pdf.
ENDWHILE.
CLOSE DATASET v_file.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data             = gd_doc_data
    put_in_outbox              = 'X'
    commit_work                = 'X'
  TABLES
    packing_list                  = it_packing_list
    contents_bin               = it_pdf
    receivers                  = it_receivers
  EXCEPTIONS
    too_many_receivers         = 1
    document_not_sent          = 2
    document_type_not_exist    = 3
    operation_no_authorization = 4
    parameter_error            = 5
    x_error                    = 6
    enqueue_error              = 7
    OTHERS                     = 8.
Regards
Nicola

Hi Nicola,
read the pdf from dataset as binary into an XSTRING.
use function to convert xstring to table.
Do not use SO_DOC.. function but CL_BCS (see blog 'unknown thus unloved'
Regards,.
Clemens

Similar Messages

  • How to upload a pdf file and download/open it

    hi experts,
      i want to upload a pdf or word format files to server and let user download or open it when user click a button, how to do that, can you post some sample codes, hunger for your advices and thanks a lot !!

    Hi,
    We have 3 types of uploads n downloads Function Modules.in ABAP.
    1. UPLOAD 
    2.WS_UPLOAD
    3.GUI_UPLOAD
    1.DOWNLOAD
    2.WS_DOWNLOAD
    3.GUI_DOWNLOAD
    Now we r making use of only GUI_UPLOAD n GUI_DOWNLOAD in our programs.
      You can go through this code which will go u an idea about the GUI_Upload n gui_download. This may lead u to understand there function modules in more detail.
    REPORT  zjavacreate message-id zmsgnew.
    ************************Creation of Internal table******************
    DATA: BEGIN OF ti_record OCCURS 200,
    Line(250),
    END OF ti_record.
    DATA: BEGIN OF ti_rec OCCURS 200,
    Line(250),
    END OF ti_rec.
    *****************************Selection screen************************
    selection-screen begin of block b1 with frame .
    Parameters create radiobutton group g1.
    PARAMETERS: JavaName(30) lower case.
    parameters modify radiobutton group g1.
    selection-screen end of block b1.
    ******************Calling the java program creation page**************
    at selection-screen.
      if CREATE = 'X'.
        if javaname is not initial.
          refresh ti_record[].
       concatenate 'public class' javaname into ti_record-line separated by space.
       concatenate ti_record-line '{' into ti_record-line separated by space.
          Append ti_record.
          ti_record-line = 'public static void main(String []args){'.
          Append ti_record.
          ti_record-line ='//enter ur code here'.
          append ti_record.
          ti_record-line ='}'.
          Append ti_record.
          ti_record-line ='}'.
          Append ti_record.
          EDITOR-CALL FOR ti_record .
        else.
          Message e001.
        endif.
    **************************Saving the java program********************
    data tfile type string.
    concatenate 'D:\Programs\' javaname '.java' into tfile.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME                        = tfile
        FILETYPE                        = 'ASC'
      TABLES
        DATA_TAB                        =   ti_record.
      endif.
    data new(15).
      if MODIFY = 'X'.
        new = 'ZJAVAMODIFY1'.
        CALL TRANSACTION NEW.
      endif.
    ZJAVAMODIFY:
    REPORT  zjavamodify.
    **********************selection screen.********************
    selection-screen begin of block b1 with frame .
    Parameters compile radiobutton group g1.
    Parameters modify radiobutton group g1.
    Parameters execute radiobutton group g1.
    PARAMETER : FILE(100) lower case.
    selection-screen end of block b1.
    DATA: BEGIN OF TI_RECORD OCCURS 1,
    LINE(200),
    END OF TI_RECORD.
    data: st1(30),st2(30).
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.
      CALL FUNCTION 'WS_FILENAME_GET'
        EXPORTING
        DEF_FILENAME           = ' '
          DEF_PATH               = '.'
        MASK                   = ' '
        MODE                   = ' '
        TITLE                  = ' '
        IMPORTING
          FILENAME               = FILE
        RC                     =
    End-of-selection.
    ****************************MODIFY********************************
      if modify = 'X'.
        data: TXT_FILE1 TYPE STRING .
        txt_file1 = file.
    **************FM GUI_UPLOAD
        CALL FUNCTION 'GUI_UPLOAD'
          EXPORTING
            FILENAME = txt_file1
          TABLES
            DATA_TAB = ti_recORD[].
    **********End FM GUI_UPLOAD
        EDITOR-CALL FOR ti_record .
    **************FM GUI_UPLOAD
        CALL FUNCTION 'GUI_DOWNLOAD'
          EXPORTING
            FILENAME = txt_file1
            FILETYPE = 'ASC'
          TABLES
            DATA_TAB = ti_record.
    **********End FM GUI_UPLOAD
      endif.
    *******************end of modify*******************
    *******************BAT file for compilation n
    execution.****************
      if compile = 'X'.
        DATA: begin of itab_bat_create occurs 0,
           row(500) type c,
          end of itab_bat_create.
        data:comp_join1(250).
        concatenate 'java' 'jCompiler' file into comp_join1
         separated
         by space.
        itab_bat_create-row = 'c:'.
        append itab_bat_create.
        itab_bat_create-row = 'cd Documents and Settings\127740'.
        append itab_bat_create.
        itab_bat_create-row = comp_join1.
        append itab_bat_create.
    ********FM GUI_DOWNLOAD
        data: st type string.
        st = 'C:\Documents and Settings\127740\compile_java.bat'.
        call function 'GUI_DOWNLOAD'
          EXPORTING
            filename         = st
            filetype         = 'ASC'
          TABLES
            data_tab         = itab_bat_create[]
          EXCEPTIONS
            file_open_error  = 1
            file_write_error = 2
            others           = 3.
    ********end FM GUI_DOWNLOAD
    *****FM dvsvas_doc_ws_execute_50
        CALL FUNCTION 'DSVAS_DOC_WS_EXECUTE_50'
          EXPORTING
            PROGRAM = 'C:\Documents and Settings\127740\compile_java.bat'.
    *****end FM dvsvas_doc_ws_execute_50
      endif.
    ***********************end of compile*******************************
    output***********************
      if execute = 'X'.
        data: TXT_FILE3 TYPE STRING .
        split File AT '.java' into: st1 st2  .
        concatenate st1 'error.txt' into TXT_FILE3.
    **************FM GUI_UPLOAD
        CALL FUNCTION 'GUI_UPLOAD'
          EXPORTING
            FILENAME = txt_file3
          TABLES
            DATA_TAB = ti_recORD[].
    **********End FM GUI_UPLOAD
        if not ti_record[] is initial.
          loop at ti_record.
            write:/ ti_record.
          endloop.
        else.
          data: TXT_FILE4 TYPE STRING .
          split File AT '.java' into: st1 st2  .
          concatenate st1 'output.txt' into TXT_FILE4.
    **************FM GUI_UPLOAD
          CALL FUNCTION 'GUI_UPLOAD'
            EXPORTING
              FILENAME = TXT_FILE4
            TABLES
              DATA_TAB = ti_recORD[].
    **********End FM GUI_UPLOAD
          loop at ti_record.
            write:/ ti_record.
          endloop.
        endif.
      endif.
    ************************end of
    output****************************************

  • How to upload a PDF file and convert it to OTF format

    We have come across rquirements like converting OTF to PDF but my requirement is to read a PDF file in SAP and convert it to OTF format for printing.
    Can anyone please help me with the Function Modules to do so.

    Hello,
    Try the following FM:
    CONVERT_OTF Convert SAP documents (SAPScript) to other types.
    Example:
    CALL FUNCTION "CONVERT_OTF"
    EXPORTING FORMAT = "PDF"
    IMPORTING BIN_FILESIZE = FILE_LEN
    TABLES OTF = OTFDATA
    LINES = PDFDATA
    EXCEPTIONS ERR_MAX_LINEWIDTH = 1
    ERR_FORMAT = 2
    ERR_CONV_NOT_POSSIBLE = 3
    OTHERS = 4.
    Hope this helps.
    Reward if helpful.
    Regards,
    Vasanth

  • Need upload a PDF document and send it as attachment

    hi all,
       i need help. i need to upload a standard pdf file and send it as attachment .. every time i use the func. module Gui_upload it corrupts the pdf file.
    is there any func. module that can serve my purpose.
    please help ..
    usefull suggestion will surely be rewarded.
    thanx in advance.
    Srinivas

    HI PRASHANT,
    thanks for ur suggestion.. i tried the format bin but it does n't work . it seems it is not able to decode  properly.
    my senario seems to be very simple..
    i have a standard pdf file which will be sent to a set of user as attachment .. the user will then download the attchment .. now  when i download it ... i `get the message that the file is corrupt..
    is there any function module... please let me know.
    thanks once again.
    srinivas

  • How to Upload a PDF file into BLOB column in a table using Forms 9i

    Can anyone tell me how to upload a PDF file from client system using File dialog window and store its content in BLOB column in a table. The file to be uploaded will be in client side.

    Hi,
    please, search a bit on the forum before do a question:
    Just searching by "upload blob pdf" ...
    How to batch upload PDF files into database BLOB
    Regards,
    Jose.

  • How to Upload a PDF file into BLOB column in a table using Forms 6i

    Can anyone tell me how to upload a PDF file from client and store its content in BLOB column in a table. The file will be genered using reports and win be stored in db.The file to be uploaded will be in client side.
    Thank´s.

    If you are using version 9 or 10 use webutil.... Look in webutil.pll.
    Use either one these two fuctions...
    FUNCTION Client_To_DB( clientFile       in VARCHAR2,
                             tableName        in VARCHAR2,
                             columnName       in VARCHAR2,
                             whereClause      in VARCHAR2,
                             asynchronous     in BOOLEAN default FALSE,
                             callbackTrigger  in VARCHAR2 default NULL) return BOOLEAN;
      FUNCTION Client_To_DB_With_Progress
                         (   clientFile       in VARCHAR2,
                             tableName        in VARCHAR2,
                             columnName       in VARCHAR2,
                             whereClause      in VARCHAR2,
                             progressTitle    in VARCHAR2,
                             progressSubTitle in VARCHAR2,
                             asynchronous     in BOOLEAN default FALSE,
                             callbackTrigger  in VARCHAR2 default NULL) return BOOLEAN;

  • How to upload a PDF file in iCloud

    Hi everybody,
    I would like to know how to upload a PDF file in iCloud. I want to share some PDF files with my iPhone, MacBook and iMac.
    Thank you a lot!

    Yes, but the problem is will iBooks remember where I left off in that pdf file? Unlikely since it was deleted.  Also, what is handy about the kindle app is once you delete it an icon appears in the app to show that this file is in the cloud. I guess for reading pdfs the kindle app is better.  I am not saying that the kindle app would be that great for other things but at least with syncing and such it's much better.  Well, iCloud is meant for other things.  It's fine because I'll just use it for those other things and stick to the kindle app for reading pdfs.  Well I use endnote for reading technical pdfs, I'm just talking about novels and such on the kindle app. 

  • How to open a pdf file and then attach it with images

    I am new to Indesign Server.
    I'm currently working on a pdf.
    I have a white blank pdf template.
    that I want to attach/glue it with images.
    How to open a pdf file and then attach it with images.
    Please, help me.
    Thanks.

    First step would be to make yourself familiar with InDesign desktop version.
    Whatever you intend to achieve, do it there manually. (see regular app docs or forums)
    Then try to automate your steps with scripting (see scripting docs or forum)
    If you can do it with a script in the desktop version, that script will likely also run in ID Server. (see server forum).
    If you can specify missing features not achievable thru scripting or manual use, reconsider to write a plugin (this forum).
    A seasoned C++ programmer will need a few months to learn the basics, wade thru tons of documentation etc. Alternatively consider to hire a consultant to do the development work for you.
    Dirk

  • I have just recorded on garageband and now need to send away for editing how do i place in file and send

    I have just recorded on garageband and now need to send away for editing how do i place in file and send 

    Send where? Edit how?

  • How to upload a PDF file, zip it and download the zipped file?

    Hi Experts,
    I have a requirement to upload a PDF file, convert that to a ZIP file and download it. If anyone has worked on this requirement, can you please guide me on this? Thanks.
    Avi

    Here you go.  Hope it helps.
    REPORT  zrich_0004.
    DATA: lt_data TYPE TABLE OF x255.
    DATA: ls_data LIKE LINE OF lt_data.
    DATA: lv_zip_content TYPE xstring.
    DATA: lv_size  TYPE i.
    DATA: lv_filename TYPE string.
    DATA: lv_path TYPE string.
    DATA: lv_fullpath TYPE string.
    DATA: lt_filetab TYPE TABLE OF file_table.
    DATA: ls_filetab LIKE LINE OF lt_filetab.
    DATA: lv_rc TYPE sy-subrc.
    DATA: lv_content TYPE xstring.
    DATA: lo_zip TYPE REF TO cl_abap_zip.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    PARAMETERS: p_up TYPE string DEFAULT 'C:\upload.pdf' .
    PARAMETERS: p_down TYPE string DEFAULT 'C:\download.zip' .
    SELECTION-SCREEN END OF BLOCK b1.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_up.
      REFRESH lt_filetab. CLEAR ls_filetab.
      cl_gui_frontend_services=>file_open_dialog(
          CHANGING
            file_table              = lt_filetab
            rc                      = lv_rc
        EXCEPTIONS
          OTHERS                  = 5 ).
      READ TABLE lt_filetab INTO ls_filetab INDEX 1.
      IF sy-subrc = 0.
        p_up = ls_filetab-filename.
      ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_down.
      CLEAR: lv_filename, lv_path, lv_fullpath.
      cl_gui_frontend_services=>file_save_dialog(
         CHANGING
           filename             = lv_filename
           path                 = lv_path
           fullpath             = lv_fullpath
         EXCEPTIONS
           OTHERS               = 4 ).
      p_down = lv_fullpath.
    START-OF-SELECTION.
      CREATE OBJECT lo_zip.
    * Read the data as a string
      cl_gui_frontend_services=>gui_upload(
        EXPORTING
          filename                = p_up
          filetype                = 'BIN'
        IMPORTING
          filelength = lv_size
        CHANGING
          data_tab                = lt_data
        EXCEPTIONS
          OTHERS                  = 19 ).
    * convert binary to xstring
      CLEAR lv_content .
      CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
        EXPORTING
          input_length = lv_size
        IMPORTING
          buffer       = lv_content
        TABLES
          binary_tab   = lt_data
        EXCEPTIONS
          failed       = 1
          OTHERS       = 2.
    * Get the file name of the uploaded file
      DATA: lv_upfilename TYPE string.
      DATA: lv_tmp TYPE char1024.
      DATA: lv_tmp_file TYPE char1024.
      lv_tmp = p_up.
      CALL FUNCTION 'STRING_REVERSE'
        EXPORTING
          string  = lv_tmp
          lang    = sy-langu
        IMPORTING
          rstring = lv_tmp.
      SPLIT lv_tmp AT '\' INTO lv_tmp_file lv_tmp.
      CALL FUNCTION 'STRING_REVERSE'
        EXPORTING
          string  = lv_tmp_file
          lang    = sy-langu
        IMPORTING
          rstring = lv_tmp_file.
      lv_upfilename = lv_tmp_file.
    * add to zip file.
      lo_zip->add( name = lv_upfilename content = lv_content ).
      lv_zip_content   = lo_zip->save( ).
    * Conver the xstring content to binary
      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          buffer        = lv_zip_content
        IMPORTING
          output_length = lv_size
        TABLES
          binary_tab    = lt_data.
    * download
      cl_gui_frontend_services=>gui_download(
          EXPORTING
            bin_filesize = lv_size
            filename     = p_down
            filetype     = 'BIN'
          CHANGING
            data_tab     = lt_data
          EXCEPTIONS
            OTHERS       = 24 ).
    Regards,
    Rich Heilman

  • How to upload the pdf file to the next view?....urgent

    Hi Experts,
    I need to upload the pdf file( a interactive form ) using the fileupload element in the A_view and the pdf file can be displayed in the b_view.
    But I don't know how to complete the function?
    Action:
    0.  Create a adobe form (c_form)in the R/3 using sfp with a inputfield.
    1.  Create a adobe interactive form (A_interactive_form)in the view(display_view) of the WDA for abap.
    2.  Create a context attribute(upload) in the display_view.
    3.  Bind the c_form to the A_interactive_form, so that the data can be transfered to the c_form.
    4.  Bind the "pdfSourth" property to context attribute "upload" in the A_interactive_form.
    4.  Type code in the WDA for abap for setting data("old") to the context.
    5.  Active the WDA and run the WDA.
    6.  In the IE, the interactive form is displayed with the value "old" in the field. Save the pdf form as "test.pdf" and close the IE.
    7.  Open the test.pdf, and type the inputfield "new" in the form, and save the test.pdf.
    8.  Create a context node(Pdfsourth) in the component controller, and create a attribute("upload") that type is xstring in the Pdfsourth.
    9.  Create a view(C_view), mapping the context node(Pdfsourth) in the component controller.
    10. Create a fileupload element in the C_view, and the "data" property is binded the "upload" attribute in the context node(Pdfsourth).
    11. Create a button(Display_form) and create the action with the outplug for upload the pdf file(test.pdf).
    12. Change the window and set the C_view as default view, and set the Navigation link from the C_view to B_view.
    13. Type code in the wddoinit method in the display_view for transfering the test.pdf file.
    method WDDOINIT .
    DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
    DATA upload                 TYPE        xstring.
    lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).
      lo_componentcontroller->getupload(
        IMPORTING
          upload = upload                         " xstring
      DATA lo_nd_pdfsourch TYPE REF TO if_wd_context_node.
      DATA lo_el_pdfsourch TYPE REF TO if_wd_context_element.
      DATA ls_pdfsourch TYPE wd_this->element_pdfsourch.
    navigate from <CONTEXT> to <PDFSOURCH> via lead selection
      lo_nd_pdfsourch = wd_context->get_child_node( name = wd_this->wdctx_pdfsourch ).
    get element via lead selection
      lo_el_pdfsourch = lo_nd_pdfsourch->get_element(  ).
    get single attribute
      lo_el_pdfsourch->set_attribute(
        EXPORTING
          name =  `UPLOAD`
          value = upload ).
    endmethod.
    15. Active the WDA and run the WDA.
    In the fileupload of the C_view, I select the test.pdf from my local machine. and click the button(Display_form), the display_view is displayed with the A_interactive_form.
    But in the A_interactive_form, the value "old" is in the field in the form rather than "new".
    I hope to display the test.pdf in the A_interactive_form. I don't know how to change my code or configuration?
    Do you give some example or some hint for this problem ?
    Thanks & Regards,
    Tao

    Now, The problem has been solved.Thanks a lot.

  • How to upload a pdf file using webdynpro abap

    Hi Experts,
    I need to upload pdf files using webdynpro abap.my question is where to upload this files and how to upload this files, and how to display this pdf file.
    Please Provide Requried Information.
    Waiting for Reply.
    Thanks & Regards.
    Bhushan.

    Hi,
    There is a UI element with the type 'File Upload'.
    You can use that in your view.
    For further details and coding, please refer to
    [http://www.****************/Tutorials/WebDynproABAP/Upload/Page1.htm]
    Hope this helps you.
    Regards,
    Dolly

  • How to upload a PDF file?

    How do I upload a pdf file so that I can edit it?

    Hi Bmayaz,
    May i know which application or service of Adobe you are using.
    If you have Adobe Acrobat you can simply open PDF document and go to Tools> content editing. And choose your tools of choice and edit the pdf document.
    If you have Acrobat.com, then you logon to www.acrobat.com and you will get couple of feature. Where you will be able to make some limited changes to document.
    Regards,
    Ajlan Huda.

  • How do I open PDF files and links

    How do I open PDF links and PDF files, heeelp! This is very confusing, I've tried everything (such as installing adobe reader etc) and nothing works for me, I'm very dissapointed with Apple right now, this suck! I'm studing and I really need this function to work for me!

    You don't need to, and should not, install any software to view PDF's. They open in Safari from the web, or in Preview from the Finder.

  • Need to Generate PDF file and send it to customer through email-ALV report

    HI All,
       I am having data in Internal table.
    can we create PDF file with out having spool-request number.
    My requirement is whenever user clicks on execute button the output is generated in PDF format automatically and then send it to customer through email.
    I found few programs in SDN for generation PDF. But problem is everyone passing the spool request to the function module.
    spool request will be generated whenever we click on print button.
    Am I correct?.
    Is there any other way to create spool request automatically. If so we can pass the this spool number to the function module.
    Regards,
    vinod.

    hi
    For sending a mail, this code will help you.
    Pls reward if help.
    FORM send_mail_2 USING msgid msgno msgv1.
    mailuser oder Gruppe like sy-uname default 'Ruckerk'.
    DATA: express_hold_time LIKE sovaltime.
    DATA: text LIKE sotxtinfo.
    DATA: receiver LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
    MESSAGE ZF100 (FTP an UDB fehlgeschlagen)
    text-msgid = msgid.
    text-msgno = msgno.
    text-msgv1 = msgv1.
    text-msgv2 = ' '.
    text-msgv3 = ' '.
    text-msgv4 = ' '.
    express_hold_time
    express_hold_time-days = 01.
    express_hold_time-h_min_sec = 240000.
    receiver
    receiver-receiver = mreceivr.
    Gruppe von Empfängern
    receiver-rec_type = 'C'.
    und Expressmeldung ausgeben
    receiver-express = 'X'.
    APPEND receiver.
    CALL FUNCTION 'MESSAGE_SEND_AS_MAIL'
    EXPORTING
    msgid = text-msgid
    msgno = text-msgno
    msgv1 = text-msgv1
    msgv2 = text-msgv2
    msgv3 = text-msgv3
    TABLES
    receivers = receiver.
    IF sy-subrc <> 0.
    WRITE:/ 'hat nicht geklappt', 'SY-SUBRC =', sy-subrc.
    ENDIF.
    PERFORM print_error_report.
    Fehlermeldung zum Abbrechen des Report's ausgeben.
    MESSAGE e398 WITH 'Jobabbruch' msgv1.
    ENDFORM. " SEND_MAIL_2
    Another Program:
    *& Report ZSENDEMAIL *
    *& Example of sending external email via SAPCONNECT *
    REPORT zsendemail .
    PARAMETERS: psubject(40) type c default 'Hello',
    p_email(40) type c default '[email protected]' .
    data: it_packing_list like sopcklsti1 occurs 0 with header line,
    it_contents like solisti1 occurs 0 with header line,
    it_receivers like somlreci1 occurs 0 with header line,
    it_attachment like solisti1 occurs 0 with header line,
    gd_cnt type i,
    gd_sent_all(1) type c,
    gd_doc_data like sodocchgi1,
    gd_error type sy-subrc.
    data: it_message type standard table of SOLISTI1 initial size 0
    with header line.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    Perform populate_message_table.
    *Send email message, although is not sent from SAP until mail send
    *program has been executed(rsconn01)
    PERFORM send_email_message.
    *Instructs mail send program for SAPCONNECT to send email(rsconn01)
    perform initiate_mail_execute_program.
    *& Form POPULATE_MESSAGE_TABLE
    Adds text to email text table
    form populate_message_table.
    Append 'Email line 1' to it_message.
    Append 'Email line 2' to it_message.
    Append 'Email line 3' to it_message.
    Append 'Email line 4' to it_message.
    endform. " POPULATE_MESSAGE_TABLE
    *& Form SEND_EMAIL_MESSAGE
    Send email message
    form send_email_message.
    Fill the document data.
    gd_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
    gd_doc_data-obj_langu = sy-langu.
    gd_doc_data-obj_name = 'SAPRPT'.
    gd_doc_data-obj_descr = psubject.
    gd_doc_data-sensitivty = 'F'.
    Describe the body of the message
    clear it_packing_list.
    refresh it_packing_list.
    it_packing_list-transf_bin = space.
    it_packing_list-head_start = 1.
    it_packing_list-head_num = 0.
    it_packing_list-body_start = 1.
    describe table it_message lines it_packing_list-body_num.
    it_packing_list-doc_type = 'RAW'.
    append it_packing_list.
    Add the recipients email address
    clear it_receivers.
    refresh it_receivers.
    it_receivers-receiver = p_email.
    it_receivers-rec_type = 'U'.
    it_receivers-com_type = 'INT'.
    it_receivers-notif_del = 'X'.
    it_receivers-notif_ndel = 'X'.
    append it_receivers.
    Call the FM to post the message to SAPMAIL
    call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    exporting
    document_data = gd_doc_data
    put_in_outbox = 'X'
    importing
    sent_to_all = gd_sent_all
    tables
    packing_list = it_packing_list
    contents_txt = it_message
    receivers = it_receivers
    exceptions
    too_many_receivers = 1
    document_not_sent = 2
    document_type_not_exist = 3
    operation_no_authorization = 4
    parameter_error = 5
    x_error = 6
    enqueue_error = 7
    others = 8.
    Store function module return code
    gd_error = sy-subrc.
    Get it_receivers return code
    loop at it_receivers.
    endloop.
    endform. " SEND_EMAIL_MESSAGE
    *& Form INITIATE_MAIL_EXECUTE_PROGRAM
    Instructs mail send program for SAPCONNECT to send email.
    form initiate_mail_execute_program.
    wait up to 2 seconds.
    if gd_error eq 0.
    submit rsconn01 with mode = 'INT'
    with output = 'X'
    and return.
    endif.
    endform. " INITIATE_MAIL_EXECUTE_PROGRAM

Maybe you are looking for