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

send mail to outlook - very urgent

My Zprogram redownloading data in Ztable1.

If the down load is successfull, i want to send outlook mail to user. how to do this? pls help me

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 08:29 AM

    check this ..

    REPORT ZMAIL.

    TABLES: ekko.

    PARAMETERS: p_email TYPE somlreci1-receiver

    • -----> mention your mail here

    TYPES: BEGIN OF t_ekpo,

    ebeln TYPE ekpo-ebeln,

    ebelp TYPE ekpo-ebelp,

    aedat TYPE ekpo-aedat,

    matnr TYPE ekpo-matnr,

    END OF t_ekpo.

    DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,

    wa_ekpo TYPE t_ekpo.

    TYPES: BEGIN OF t_charekpo,

    ebeln(10) TYPE c,

    ebelp(5) TYPE c,

    aedat(8) TYPE c,

    matnr(18) TYPE c,

    END OF t_charekpo.

    DATA: wa_charekpo TYPE t_charekpo.

    DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

    WITH HEADER LINE.

    DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

    WITH HEADER LINE.

    DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

    t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

    t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    w_cnt TYPE i,

    w_sent_all(1) TYPE c,

    w_doc_data LIKE sodocchgi1,

    gd_error TYPE sy-subrc,

    gd_reciever TYPE sy-subrc.

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

    *START_OF_SELECTION

    START-OF-SELECTION.

    • Retrieve sample data from table ekpo

    PERFORM data_retrieval.

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

    PERFORM build_xls_data_table.

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

    *END-OF-SELECTION

    END-OF-SELECTION.

    • Populate message body text

    perform populate_email_message_body.

    • Send file by email as .xls speadsheet

    PERFORM send_file_as_email_attachment

    tables it_message

    it_attach

    using p_email

    'Example .xls documnet attachment'

    'XLS'

    'filename'

    ' '

    ' '

    ' '

    changing gd_error

    gd_reciever.

    • Instructs mail send program for SAPCONNECT to send email(rsconn01)

    PERFORM initiate_mail_execute_program.

    &----


    *& Form DATA_RETRIEVAL

    &----


    • Retrieve data form EKPO table and populate itab it_ekko

    ----


    FORM data_retrieval.

    SELECT ebeln ebelp aedat matnr

    UP TO 10 ROWS

    FROM ekpo

    INTO TABLE it_ekpo.

    ENDFORM. " DATA_RETRIEVAL

    &----


    *& Form BUILD_XLS_DATA_TABLE

    &----


    • Build data table for .xls document

    ----


    FORM build_xls_data_table.

    data: ld_store(50) type c. "Leading zeros

    CONSTANTS: con_cret(5) TYPE c VALUE '0D', "OK for non Unicode

    con_tab(5) TYPE c VALUE '09'. "OK for non Unicode

    *If you have Unicode check active in program attributes thnen you will

    *need to declare constants as follows

    *class cl_abap_char_utilities definition load.

    *constants:

    • con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,

    • con_cret type c value cl_abap_char_utilities=>CR_LF.

    CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR' INTO it_attach SEPARATED BY con_tab.

    CONCATENATE con_cret it_attach INTO it_attach.

    APPEND it_attach.

    LOOP AT it_ekpo INTO wa_charekpo.

    *Modification to retain leading zeros

    • inserts code for excell REPLACE command into ld_store

    • =REPLACE("00100",1,5,"00100")

    concatenate '=REPLACE("' wa_charekpo-ebelp '",1,5,"'

    wa_charekpo-ebelp '")' into ld_store .

    • concatenate ld_store into .xls file instead of actual value(ebelp)

    CONCATENATE wa_charekpo-ebeln ld_store wa_charekpo-aedat wa_charekpo-matnr INTO it_attach SEPARATED BY con_tab.

    CONCATENATE con_cret it_attach INTO it_attach.

    APPEND it_attach.

    ENDLOOP.

    ENDFORM. " BUILD_XLS_DATA_TABLE

    &----


    *& Form SEND_FILE_AS_EMAIL_ATTACHMENT

    &----


    • Send email

    ----


    FORM send_file_as_email_attachment tables pit_message

    pit_attach

    using p_email

    p_mtitle

    p_format

    p_filename

    p_attdescription

    p_sender_address

    p_sender_addres_type

    changing p_error

    p_reciever.

    DATA: ld_error TYPE sy-subrc,

    ld_reciever TYPE sy-subrc,

    ld_mtitle LIKE sodocchgi1-obj_descr,

    ld_email LIKE somlreci1-receiver,

    ld_format TYPE so_obj_tp ,

    ld_attdescription TYPE so_obj_nam ,

    ld_attfilename TYPE so_obj_des ,

    ld_sender_address LIKE soextreci1-receiver,

    ld_sender_address_type LIKE soextreci1-adr_typ,

    ld_receiver LIKE sy-subrc.

    ld_email = p_email.

    ld_mtitle = p_mtitle.

    ld_format = p_format.

    ld_attdescription = p_attdescription.

    ld_attfilename = p_filename.

    ld_sender_address = p_sender_address.

    ld_sender_address_type = p_sender_addres_type.

    • Fill the document data.

    w_doc_data-doc_size = 1.

    • Populate the subject/generic message attributes

    w_doc_data-obj_langu = sy-langu.

    w_doc_data-obj_name = 'SAPRPT'.

    w_doc_data-obj_descr = ld_mtitle .

    w_doc_data-sensitivty = 'F'.

    • Fill the document data and get size of attachment

    CLEAR w_doc_data.

    READ TABLE it_attach INDEX w_cnt.

    w_doc_data-doc_size =

    ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).

    w_doc_data-obj_langu = sy-langu.

    w_doc_data-obj_name = 'SAPRPT'.

    w_doc_data-obj_descr = ld_mtitle.

    w_doc_data-sensitivty = 'F'.

    CLEAR t_attachment.

    REFRESH t_attachment.

    t_attachment[] = pit_attach[].

    • Describe the body of the message

    CLEAR t_packing_list.

    REFRESH t_packing_list.

    t_packing_list-transf_bin = space.

    t_packing_list-head_start = 1.

    t_packing_list-head_num = 0.

    t_packing_list-body_start = 1.

    DESCRIBE TABLE it_message LINES t_packing_list-body_num.

    t_packing_list-doc_type = 'RAW'.

    APPEND t_packing_list.

    • Create attachment notification

    t_packing_list-transf_bin = 'X'.

    t_packing_list-head_start = 1.

    t_packing_list-head_num = 1.

    t_packing_list-body_start = 1.

    DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.

    t_packing_list-doc_type = ld_format.

    t_packing_list-obj_descr = ld_attdescription.

    t_packing_list-obj_name = ld_attfilename.

    t_packing_list-doc_size = t_packing_list-body_num * 255.

    APPEND t_packing_list.

    • Add the recipients email address

    CLEAR t_receivers.

    REFRESH t_receivers.

    t_receivers-receiver = ld_email.

    t_receivers-rec_type = 'U'.

    t_receivers-com_type = 'INT'.

    t_receivers-notif_del = 'X'.

    t_receivers-notif_ndel = 'X'.

    APPEND t_receivers.

    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

    EXPORTING

    document_data = w_doc_data

    put_in_outbox = 'X'

    sender_address = ld_sender_address

    sender_address_type = ld_sender_address_type

    commit_work = 'X'

    IMPORTING

    sent_to_all = w_sent_all

    TABLES

    packing_list = t_packing_list

    contents_bin = t_attachment

    contents_txt = it_message

    receivers = t_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.

    • Populate zerror return code

    ld_error = sy-subrc.

    • Populate zreceiver return code

    LOOP AT t_receivers.

    ld_receiver = t_receivers-retrn_code.

    ENDLOOP.

    ENDFORM.

    &----


    *& Form INITIATE_MAIL_EXECUTE_PROGRAM

    &----


    • Instructs mail send program for SAPCONNECT to send email.

    ----


    FORM initiate_mail_execute_program.

    WAIT UP TO 2 SECONDS.

    SUBMIT rsconn01 WITH mode = 'INT'

    WITH output = 'X'

    AND RETURN.

    ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM

    &----


    *& Form POPULATE_EMAIL_MESSAGE_BODY

    &----


    • Populate message body text

    ----


    form populate_email_message_body.

    REFRESH it_message.

    it_message = 'Please find attached a list test ekpo records'.

    APPEND it_message.

    endform. " POPULATE_EMAIL_MESSAGE_BODY

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      then use this..

      &----


      *& Report ZSENDEMAIL *

      *& *

      &----


      *& Example of sending external email via SAPCONNECT *

      *& *

      &----


      REPORT zsendemail .

      PARAMETERS: psubject(40) type c default 'Hello',

      p_email(40) type c.

      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

  • Posted on Jun 17, 2008 at 08:33 AM

    Hi Kumar,

    Pls have a look on below link

    http://www.sapdevelopment.co.uk/reporting/email/emailhome.htm

    also u can use below FMs

    SO_OBJECT_SEND

    SO_NEW_DOCUMENT_ATT_SEND_API1

    SO_DOCUMENT_SEND_API1

    Search forum for this FMs... u will get many examples..

    Hope it will solve your problem..

    Reward points if useful..

    Thanks & Regards

    ilesh 24x7

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 08:34 AM

    Hi Kumar,

    See the link for code

    http://www.sapdevelopment.co.uk/reporting/email/email_mbody.htm

    Regards

    Kiran Sure

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 17, 2008 at 08:46 AM

    Hi Kiran,

    I think u would like to see below Thread... Same as urs...

    See the sample code below as well...

    Email ITAB structure

    DATA: BEGIN OF EMAIL_ITAB OCCURS 10.
    
    INCLUDE STRUCTURE SOLI.
    
    DATA: END OF EMAIL_ITAB.
    
    
    DATA: T_EMAIL LIKE SOOS1-RECEXTNAM. "EMail *distribution list
    
    CONSTANTS: C_EMAIL_DISTRIBUTION LIKE SOOS1-RECEXTNAM VALUE
    
    ‘abc@here.com,abc@there.com’.
    
    
    
    
    *Initialization 
    
    REFRESH EMAIL_ITAB.
    
    
    
    *Populate data 
    
    EMAIL_ITAB-LINE = ‘Email body text 1’.
    
    APPEND EMAIL_ITAB.
    
    EMAIL_ITAB-LINE = ‘Email body text 2’.
    
    APPEND EMAIL_ITAB.
    
    
    T_EMAIL = C_EMAIL_DISTRIBUTION.
    
    
    
    
    *--- EMAIL FUNCTION
    --------------------------------------------------------------------------------
     
    
    
    REQUIRMENTS: 
    
    
    1) The user running the program needs a valid email address in their 
    
    
    address portion of tx SU01 under external comms -> SMTP -> internet 
    
    
    address. 
    
    
    2) A job called SAP_EMAIL is running with the following parameters: 
    
    
    Program: RSCONN01 Variant: INT User: XXX 
    
    
    This program moves mail from the outbox to the mail server using 
    
    
    RFC destination: SAP_INTERNET_GATEWAY_SERVER 
    
    
    INTERFACE: 
    
    
    1) APPLICATION: Anything 
    
    
    2) EMAILTITLE: EMail subject 
    
    
    3) RECEXTNAM: EMail distribution lists separated by commas 
    
    
    4) TEXTTAB: Internal table for lines of the email message 
    
    
    EXCEPTIONS: 
    
    
    Send OK = 0 otherwise there was a problem with the send. 
    
    *
    --------------------------------------------------------------------------------
     
    CALL FUNCTION 'Z_SEND_EMAIL_ITAB'
    
    EXPORTING
    
    APPLICATION = 'EMAIL'
    
    EMAILTITLE = 'Email Subject'
    
    RECEXTNAM = T_EMAIL
    
    TABLES
    
    TEXTTAB = EMAIL_ITAB
    
    EXCEPTIONS
    
    OTHERS = 1.
    
    Function Z_SEND_EMAIL_ITAB
    ""Local interface:
    
    *" IMPORTING
    
    *" VALUE(APPLICATION) LIKE SOOD1-OBJNAM
    
    *" VALUE(EMAILTITLE) LIKE SOOD1-OBJDES
    
    *" VALUE(RECEXTNAM) LIKE SOOS1-RECEXTNAM
    
    *" TABLES
    
    *" TEXTTAB STRUCTURE SOLI
    
    *"------------------------------------------------------------------
    
    
    
    
    local data declaration 
    
    DATA: OHD LIKE SOOD1,
    
    OID LIKE SOODK,
    
    TO_ALL LIKE SONV-FLAG,
    
    OKEY LIKE SWOTOBJID-OBJKEY.
    
    DATA: BEGIN OF RECEIVERS OCCURS 0.
    
    INCLUDE STRUCTURE SOOS1.
    
    DATA: END OF RECEIVERS.
    
    
    
    
    fill odh 
    
    CLEAR OHD.
    
    OHD-OBJLA = SY-LANGU.
    
    OHD-OBJNAM = APPLICATION.
    
    OHD-OBJDES = EMAILTITLE.
    
    OHD-OBJPRI = 3.
    
    OHD-OBJSNS = 'F'.
    
    OHD-OWNNAM = SY-UNAME.
    
    
    
    
    send Email 
    
    CONDENSE RECEXTNAM NO-GAPS.
    
    CHECK RECEXTNAM SPACE AND RECEXTNAM CS '@'.
    
    
    
    
    for every individual recipient send an Email 
    
    
    (see OSS message 0120050409/0000362105/1999) 
    
    WHILE RECEXTNAM CS ','.
    
    PERFORM INIT_REC TABLES RECEIVERS.
    
    READ TABLE RECEIVERS INDEX 1.
    
    RECEIVERS-RECEXTNAM = RECEXTNAM+0(SY-FDPOS).
    
    ADD 1 TO SY-FDPOS.
    
    SHIFT RECEXTNAM LEFT BY SY-FDPOS PLACES.
    
    MODIFY RECEIVERS INDEX 1.
    
    PERFORM SO_OBJECT_SEND_REC
    
    TABLES TEXTTAB RECEIVERS
    
    USING OHD.
    
    ENDWHILE.
    
    
    
    
    check last recipient in recipient list 
    
    IF RECEXTNAM SPACE.
    
    PERFORM INIT_REC TABLES RECEIVERS.
    
    READ TABLE RECEIVERS INDEX 1.
    
    RECEIVERS-RECEXTNAM = RECEXTNAM.
    
    MODIFY RECEIVERS INDEX 1.
    
    PERFORM SO_OBJECT_SEND_REC
    
    TABLES TEXTTAB RECEIVERS
    
    USING OHD.
    
    ENDIF.
    
    
    ENDFUNCTION.
    
    
    
    ---------------------------------------------------------------------
    
    
    
    FORM SO_OBJECT_SEND_REC * 
    
    ---------------------------------------------------------------------
    
    FORM SO_OBJECT_SEND_REC
    
    TABLES OBJCONT STRUCTURE SOLI
    
    RECEIVERS STRUCTURE SOOS1
    
    USING OBJECT_HD STRUCTURE SOOD1.
    
    
    DATA: OID LIKE SOODK,
    
    TO_ALL LIKE SONV-FLAG,
    
    OKEY LIKE SWOTOBJID-OBJKEY.
    
    
    
    CALL FUNCTION 'SO_OBJECT_SEND'
    
    EXPORTING
    
    EXTERN_ADDRESS = 'X'
    
    OBJECT_HD_CHANGE = OBJECT_HD
    
    OBJECT_TYPE = 'RAW'
    
    OUTBOX_FLAG = 'X'
    
    SENDER = SY-UNAME
    
    IMPORTING
    
    OBJECT_ID_NEW = OID
    
    SENT_TO_ALL = TO_ALL
    
    OFFICE_OBJECT_KEY = OKEY
    
    TABLES
    
    OBJCONT = OBJCONT
    
    RECEIVERS = RECEIVERS
    
    EXCEPTIONS
    
    ACTIVE_USER_NOT_EXIST = 1
    
    COMMUNICATION_FAILURE = 2
    
    COMPONENT_NOT_AVAILABLE = 3
    
    FOLDER_NOT_EXIST = 4
    
    FOLDER_NO_AUTHORIZATION = 5
    
    FORWARDER_NOT_EXIST = 6
    
    NOTE_NOT_EXIST = 7
    
    OBJECT_NOT_EXIST = 8
    
    OBJECT_NOT_SENT = 9
    
    OBJECT_NO_AUTHORIZATION = 10
    
    OBJECT_TYPE_NOT_EXIST = 11
    
    OPERATION_NO_AUTHORIZATION = 12
    
    OWNER_NOT_EXIST = 13
    
    PARAMETER_ERROR = 14
    
    SUBSTITUTE_NOT_ACTIVE = 15
    
    SUBSTITUTE_NOT_DEFINED = 16
    
    SYSTEM_FAILURE = 17
    
    TOO_MUCH_RECEIVERS = 18
    
    USER_NOT_EXIST = 19
    
    X_ERROR = 20
    
    OTHERS = 21.
    
    IF SY-SUBRC 0.
    
    RAISE OTHERS.
    
    ENDIF.
    
    ENDFORM.
    
    
    
    ---------------------------------------------------------------------
    
    
    
    FORM INIT_REC * 
    
    ---------------------------------------------------------------------
    
    FORM INIT_REC TABLES RECEIVERS STRUCTURE SOOS1.
    
    CLEAR RECEIVERS.
    
    REFRESH RECEIVERS.
    
    MOVE SY-DATUM TO RECEIVERS-RCDAT .
    
    MOVE SY-UZEIT TO RECEIVERS-RCTIM.
    
    MOVE '1' TO RECEIVERS-SNDPRI.
    
    MOVE 'X' TO RECEIVERS-SNDEX.
    
    MOVE 'U-' TO RECEIVERS-RECNAM.
    
    MOVE 'U' TO RECEIVERS-RECESC.
    
    MOVE 'INT' TO RECEIVERS-SNDART.
    
    MOVE '5' TO RECEIVERS-SORTCLASS.
    
    APPEND RECEIVERS.
    
    ENDFORM.

    Hope it will solve your problem..

    Reward points if useful..

    Thanks & Regards

    ilesh 24x7

    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.