Skip to Content
author's profile photo Former Member
Former Member

Send Mail with Attachment to Outlook - Version 3.1i

Hi Every one,

I need to draft a logic in 3.1i system that sends a mail to Microsoft outlook inbox with attachments.

The below flow of logic is the core part of the code that I am using for mails without attachments.

OPEN DATASET P_FNAME FOR OUTPUT IN TEXT MODE.

IF P_FROM NE SPACE.

CONCATENATE 'From:'(MFR) P_FROM INTO P_FROM SEPARATED BY SPACE.

TRANSFER P_FROM TO P_FNAME.

ENDIF.

IF P_TO NE SPACE.

CONCATENATE 'To:'(MTO) P_TO INTO P_TO SEPARATED BY SPACE.

TRANSFER P_TO TO P_FNAME.

ENDIF.

IF P_CC NE SPACE.

CONCATENATE 'Cc:'(MCC) P_CC INTO P_CC SEPARATED BY SPACE.

TRANSFER P_CC TO P_FNAME.

ENDIF.

IF P_BCC NE SPACE.

CONCATENATE 'Bcc:'(MBC) P_BCC INTO P_BCC SEPARATED BY SPACE.

TRANSFER P_BCC TO P_FNAME.

ENDIF.

IF P_SUB NE SPACE.

CONCATENATE 'Subject:'(MSB) P_SUB INTO P_SUB SEPARATED BY SPACE.

TRANSFER P_SUB TO P_FNAME.

ENDIF.

LOOP AT S_BODY.

TRANSFER S_BODY-LOW TO P_FNAME.

ENDLOOP.

CLOSE DATASET P_FNAME.

************************************************************************

  • Run External Command: SENDMAIL

CLEAR PARCOM.

REFRESH OUT_LINES.

concatenate 'sendmail -t < ' p_fname into parcom.

  • Execute Command

call 'system' id 'COMMAND' field PARCOM id 'TAB' field out_lines-SYS .

I have tried creating another file in AL11 and using it as attachment after the transfer of subject text in the above code, like -

CONCATENATE 'Attach:'(MAT) '/usr/sap/GS1/DVEBMGS20/work/attach.txt INTO P_ATTACH SEPARATED BY SPACE.

TRANSFER P_ATTACH TO P_FNAME.

But, this did not work.

Need your help in extending the code to send attachments.

Thanks in Advance,

Regards

Govardhan

Edited by: Gova12 on Sep 8, 2009 12:25 PM

Edited by: Gova12 on Sep 8, 2009 12:57 PM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 08, 2009 at 11:09 AM

    Hi,

    Refer to the link given to send output as attachment:

    sending-sap-script-output-to-email

    Function module 'SO_DOCUMENT_SEND_API1' is used for this purpose.

    Regards,

    Rajesh Kumar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 08, 2009 at 11:11 AM

    < DATA: i_message TYPE STANDARD TABLE OF solisti1,

    i_attach TYPE STANDARD TABLE OF solisti1,

    i_attach_body TYPE STANDARD TABLE OF solisti1,

    i_suc_notify TYPE STANDARD TABLE OF zifdl,

    i_mail_rcpnts TYPE STANDARD TABLE OF zbss_mail.

    • Populate table with detaisl to be entered into .xls file

    PERFORM build_xls_data_table.

    • Send file by email as .xls speadsheet

    PERFORM send_file_as_email_attachment.

    &----


    *& Form BUILD_XLS_DATA_TABLE

    &----


    • Populate table with detaisl to be entered into .xls file

    ----


    FORM build_xls_data_table .

    CONSTANTS: l_c_head1 TYPE char20 VALUE 'Credit Card Type', "#EC NOTEXT

    l_c_head2 TYPE char20 VALUE 'OrigSysRef',

    l_c_head3 TYPE char20 VALUE 'OrderNum',

    l_c_head4 TYPE char20 VALUE 'OrigSysLineRef',

    l_c_head5 TYPE char20 VALUE 'LineNum',

    l_c_head6 TYPE char20 VALUE 'ItemNum',

    l_c_head7 TYPE char20 VALUE 'LineAmt',

    l_c_head8 TYPE char20 VALUE 'ScheduleDate',

    l_c_head9 TYPE char20 VALUE 'ReqDate',

    l_c_head10 TYPE char20 VALUE 'PromiseDate',

    l_c_head11 TYPE char20 VALUE 'AuthReqDate'.

    DATA:

    l_vtext TYPE char50, "Credit Card Type

    l_bstnk TYPE char20, "OrigSysRef

    l_vbeln TYPE char20, "OrderNum

    l_posex TYPE char20, "OrigSysLineRef

    l_posnr TYPE char20, "LineNum

    l_matnr TYPE char20, "ItemNum

    l_netwr TYPE char20, "LineAmt

    l_lddat TYPE char20, "ScheduleDate

    l_vdatu TYPE char20, "ReqDate

    l_edatu TYPE char20, "PromiseDate

    l_req_date TYPE char20, "AuthReqDate

    l_sub_tot TYPE vbap-netwr,

    l_sto TYPE char20,

    l_v_datum TYPE char10,

    l_v_time TYPE char10,

    l_dummy TYPE char20.

    DATA: l_wa_attach TYPE solisti1,

    l_wa_attach_body TYPE solisti1,

    l_wa_final TYPE t_final.

    CLEAR: l_dummy.

    CONCATENATE sy-datum(4) sy-datum4(2) sy-datum6(2) INTO l_v_datum SEPARATED BY '/'.

    CONCATENATE sy-uzeit(2) sy-uzeit2(2) sy-uzeit4(2) INTO l_v_time SEPARATED BY ':'.

      • This table contain actual column headings for the fields in the attachment

      CLEAR: l_wa_attach.

      CONCATENATE text-011

      cl_abap_char_utilities=>horizontal_tab

      text-003

      cl_abap_char_utilities=>horizontal_tab

      cl_abap_char_utilities=>horizontal_tab

      cl_abap_char_utilities=>horizontal_tab

      text-021

      l_v_datum

      l_v_time

      cl_abap_char_utilities=>cr_lf

      cl_abap_char_utilities=>cr_lf

      INTO l_wa_attach SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

      APPEND l_wa_attach TO i_attach.

      CLEAR: l_wa_attach.

      • This table contain actual column headings for the fields in the attachment

      CONCATENATE l_c_head1 l_c_head2 l_c_head3 l_c_head4 l_c_head5

      l_c_head6 l_c_head7 l_c_head8 l_c_head9 l_c_head10

      l_c_head11 cl_abap_char_utilities=>cr_lf

      INTO l_wa_attach SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

      APPEND l_wa_attach TO i_attach.

      CLEAR: l_wa_attach.

      • This table contain the actual contents of the attachment

      SORT i_final BY vbeln posnr.

      CLEAR: l_wa_final,l_wa_attach_body.

      LOOP AT i_final INTO l_wa_final.

      WRITE :

      l_wa_final-vtext TO l_vtext,

      l_wa_final-bstnk TO l_bstnk,

      l_wa_final-vbeln TO l_vbeln,

      l_wa_final-posex TO l_posex,

      l_wa_final-posnr TO l_posnr,

      l_wa_final-matnr TO l_matnr,

      l_wa_final-netwr TO l_netwr CURRENCY 'VBAP-WAERK',

      l_wa_final-lddat TO l_lddat,

      l_wa_final-vdatu TO l_vdatu,

      l_wa_final-edatu TO l_edatu,

      l_wa_final-req_date TO l_req_date.

      l_sub_tot = l_sub_tot + l_wa_final-netwr.

      CONCATENATE l_dummy

      l_vtext l_bstnk l_vbeln l_posex l_posnr l_matnr

      l_netwr l_lddat l_vdatu l_edatu l_req_date

      INTO l_wa_attach_body SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

      APPEND l_wa_attach_body TO i_attach_body.

      CLEAR: l_wa_attach_body.

      AT END OF vbeln.

      READ TABLE i_final INTO l_wa_final INDEX sy-tabix.

      MOVE l_sub_tot TO l_sto.

      CONCATENATE cl_abap_char_utilities=>horizontal_tab

      cl_abap_char_utilities=>horizontal_tab

      cl_abap_char_utilities=>horizontal_tab

      'Order total'

      l_sto

      cl_abap_char_utilities=>cr_lf

      INTO l_wa_attach_body SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

      APPEND l_wa_attach_body TO i_attach_body.

      CLEAR: l_sub_tot,l_sto,l_wa_attach_body.

      ENDAT.

      ENDLOOP.

      ENDFORM. " BUILD_XLS_DATA_TABLE

      DATA: l_v_desc TYPE sood1-objdes,

      l_wa_suc_notify TYPE zifdl,

      l_wa_mail_rcpnts TYPE zbss_mail.

      • Get the mail ids from distribution list

      REFRESH: i_suc_notify.

      SELECT * INTO TABLE i_suc_notify

      FROM zifdl

      WHERE zdstlist EQ p_disid.

      IF sy-subrc <> c_zero.

      • Show exit msg if there is no distribution list maintained

      MESSAGE e002 WITH text-014 p_disid.

      ENDIF.

      • format the email id details

      CLEAR: l_wa_suc_notify,l_wa_mail_rcpnts.

      LOOP AT i_suc_notify INTO l_wa_suc_notify .

      IF l_wa_suc_notify-zuserid CA '@'.

      l_wa_mail_rcpnts-l_adr_name = l_wa_suc_notify-zuserid.

      ELSE.

      l_wa_mail_rcpnts-usrnam = l_wa_suc_notify-zuserid.

      ENDIF.

      APPEND l_wa_mail_rcpnts TO i_mail_rcpnts.

      CLEAR: l_wa_mail_rcpnts,l_wa_suc_notify.

      ENDLOOP.

      • Populate message body text

      PERFORM populate_email_message_body.

      • Send the report output generated to the list of recipients

      MOVE text-012 TO l_v_desc.

      • Send the e-mail with attachment

      TRY.

      • -------- create persistent send request ------------------------

      send_request = cl_bcs=>create_persistent( ).

      • -------- create and set document with attachment ---------------

      • create document from internal table with text

      document = cl_document_bcs=>create_document(

      i_type = 'RAW'

      i_text = i_content_body[]

      i_subject = subject ).

      • Check if Attachment should be sent in mail

      IF p_skip_attach IS INITIAL.

      IF i_attachment_type = 'ALI'.

      CALL METHOD document->add_attachment

      EXPORTING

      i_attachment_type = i_attachment_type

      i_attachment_subject = l_filename

      i_att_content_hex = i_content_hex.

      ELSE.

      • Get No of lines

      DESCRIBE TABLE i_attach LINES l_lines.

      • Size to multiplied by no of lines

      l_size = l_lines * 255.

      CALL METHOD document->add_attachment

      EXPORTING

      i_attachment_type = i_attachment_type

      i_attachment_size = l_size

      i_attachment_subject = i_filename

      i_att_content_text = i_attach[].

      ENDIF.

      ENDIF.

      • add document to send request

      CALL METHOD send_request->set_document( document ).

      • --------- add recipient (e-mail address) -----------------------

      LOOP AT i_receivers INTO l_receiver_wa.

      CLEAR l_mailaddr.

      l_mailaddr = l_receiver_wa-receiver.

      recipient = cl_cam_address_bcs=>create_internet_address(

      l_mailaddr ).

      • add recipient with its respective attributes to send request

      CALL METHOD send_request->add_recipient

      EXPORTING

      i_recipient = recipient

      i_express = express

      • i_copy = ' '

      • i_blind_copy = ' '

      i_copy = l_receiver_wa-copy

      i_blind_copy = l_receiver_wa-blind_copy

      i_no_forward = ' '.

      ENDLOOP.

      *Set sender based on l_userid

      lo_sender = cl_sapuser_bcs=>create( l_userid ).

      CALL METHOD send_request->set_sender( EXPORTING i_sender = lo_sender ).

      • ---------- send document ---------------------------------------

      CALL METHOD send_request->send(

      EXPORTING

      i_with_error_screen = 'X'

      RECEIVING

      result = sent_to_all ).

      IF i_bypass_commit IS INITIAL.

      COMMIT WORK.

      ENDIF.

      • -----------------------------------------------------------

      • * exception handling

      • -----------------------------------------------------------

      CATCH cx_bcs INTO bcs_exception.

      ENDTRY. >

      Edited by: sugunav on Sep 8, 2009 4:41 PM

      Add a comment
      10|10000 characters needed characters exceeded

    Before answering

    You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
    You must be Logged in to submit an answer.

    Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.