Skip to Content
avatar image
Former Member

what is the function module used to send an email

hi

what is the function module used to send an email

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 17, 2007 at 06:02 AM

    Hi,

    you can use

    SO_NEW_DOCUMENT_ATT_SEND_API1

    this is to send with attachment.

    to send without attachment

    SO_NEW_DOCUMENT_SEND_API1

    Check this,

    For API

    data: maildata type sodocchgi1.

    data: mailtxt type table of solisti1 with header line.

    data: mailrec type table of somlrec90 with header line.

    start-of-selection.

    clear: maildata, mailtxt, mailrec.

    refresh: mailtxt, mailrec.

    maildata-obj_name = 'TEST'.

    maildata-obj_descr = 'Test'.

    maildata-obj_langu = sy-langu.

    mailtxt-line = 'This is a test'.

    append mailtxt.

    mailrec-receiver = sy-uname.

    mailrec-rec_type = 'B'.

    append mailrec.

    call function 'SO_NEW_DOCUMENT_SEND_API1'

    exporting

    document_data = maildata

    document_type = 'RAW'

    put_in_outbox = 'X'

    tables

    object_header = mailtxt

    object_content = mailtxt

    receivers = mailrec

    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.

    if sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    endif.

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 17, 2007 at 06:02 AM

    FM : SO_DOCUMENT_SEND_API1

    A sample program :

    https://wiki.sdn.sap.com/wiki/display/Snippets/Sendingmailwith+attachment

    https://wiki.sdn.sap.com/wiki/display/Snippets/MailsfromSAPtoexternalmailidwithHTML+formatting

    Regards,

    Anish Thomas

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 17, 2007 at 06:01 AM

    CV_SWE_EVENT_MAIL Send mail as recipient of events

    MASS_EINE_SEND_MAIL Send mail to inform user about save errors

    MASS_EKKO_SEND_MAIL Send mail to inform user about save errors

    MASS_MARC_SEND_MAIL Send mail to inform user about save errors

    MASS_VENDOR_SEND_MAIL Send mail to inform user about save errors

    SWWM Send mails from and to work items

    Regards

    Nilesh

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 17, 2007 at 06:02 AM

    so_new_document_send_api1

    so_new_document_att_send_api1

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 17, 2007 at 06:04 AM

    Hi,

    Chekc this program it may help u.

    FORM send_mail USING p_y16m_rcp_par STRUCTURE y16m_rcp_par.

    • Have a subject for the mail

    g_s_document_data-obj_name = text-t02.

    g_s_document_data-obj_descr = text-t03.

    • Fill receiver information

    g_s_receivers-rec_type = p_y16m_rcp_par-rec_type.

    g_s_receivers-rec_id = p_y16m_rcp_par-rec_id.

    g_s_receivers-express = 'X'.

    APPEND g_s_receivers TO g_t_receivers.

    • Call function to send mail

    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

    EXPORTING

    document_data = g_s_document_data

    document_type = 'RAW'

    • PUT_IN_OUTBOX = ' '

    • IMPORTING

    • SENT_TO_ALL =

    • NEW_OBJECT_ID =

    TABLES

    • OBJECT_HEADER =

    object_content = g_t_object_content

    • CONTENTS_HEX =

    • OBJECT_PARA =

    • OBJECT_PARB =

    receivers = g_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

    .

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    ENDFORM. " SEND_MAIL

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 17, 2007 at 06:06 AM

    Hello,

    Try this, It will help you. Sure.

    Regards,

    Rakesh.

    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.
    
    
      TYPES: BEGIN OF typ_item,
             asno(10) TYPE c,
             matnr TYPE mseg-matnr,
             maktx TYPE makt-maktx,
             menge TYPE mseg-menge,
             meins TYPE mseg-meins,
             END OF typ_item.
    
      DATA: wrk_menge(17) TYPE c.
      DATA: sum_srno TYPE i VALUE 0.
      DATA: wrk_srno TYPE n.
    
    *Internal tables
    *----------------------------------------------------------------------*
      DATA: it_std_objhdr  TYPE TABLE OF solisti1.
      DATA: it_std_objcnt  TYPE TABLE OF solisti1.
      DATA: it_std_rcvlst  TYPE TABLE OF somlreci1.
      DATA: it_std_objtxt  TYPE TABLE OF solisti1..
      DATA: it_std_objpack TYPE TABLE OF sopcklsti1 .
      DATA: it_std_cntbin  TYPE TABLE OF solisti1.
    
      DATA: it_std_items TYPE TABLE OF typ_item.
      DATA: is_items LIKE LINE OF it_std_items.
    *  DATA: it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE.
    *  DATA: wa_attachment TYPE solisti1.
    
    * Internal structures
    *----------------------------------------------------------------------*
      DATA: is_docdata LIKE sodocchgi1.
      DATA: is_objhdr  LIKE LINE OF it_std_objhdr.
      DATA: is_objcnt  LIKE LINE OF it_std_objcnt.
      DATA: is_rcvlst  LIKE LINE OF it_std_rcvlst.
      DATA: is_objtxt  LIKE LINE OF it_std_objtxt.
      DATA: is_objpack LIKE LINE OF it_std_objpack.
      DATA: is_cntbin  LIKE LINE OF it_std_cntbin.
    
    
    *Work variables
    *----------------------------------------------------------------------*
      DATA: wrk_lines TYPE i.
    
    
    
    
      is_docdata-obj_descr = 'Movement of parts to processor'.
    
    
    
    *Cover letter of the mail
      is_objtxt = 'Dear Sir,'.
      APPEND is_objtxt TO it_std_objtxt.
    
      is_objtxt = ' '.
      APPEND is_objtxt TO it_std_objtxt.
    
    
      is_objtxt = text-001.
      APPEND is_objtxt TO it_std_objtxt.
    
    
      is_objtxt = text-002.
      APPEND is_objtxt TO it_std_objtxt.
    
      is_objtxt = text-003.
      APPEND is_objtxt TO it_std_objtxt.
    
      is_objtxt = ' '.
      APPEND is_objtxt TO it_std_objtxt.
    
      is_objtxt = 'Thanks n Regards,'.
      APPEND is_objtxt TO it_std_objtxt.
    
      is_objtxt = ' '.
      APPEND is_objtxt TO it_std_objtxt.
    
      is_objtxt = 'abc MOTORS'.
      APPEND is_objtxt TO it_std_objtxt.
    
    
    * Write Packing List (Main)
    
      DESCRIBE TABLE it_std_objtxt LINES wrk_lines.
      READ TABLE it_std_objtxt INTO is_objtxt INDEX wrk_lines.
    
      is_docdata-doc_size = ( wrk_lines - 1 ) * 255 + STRLEN( is_objtxt ).
    
    
      CLEAR is_objpack-transf_bin.
    
      is_objpack-head_start = 1.
      is_objpack-head_num   = 0.
      is_objpack-body_start = 1.
      is_objpack-body_num   = wrk_lines.
      is_objpack-doc_type   = 'RAW'.
    
      APPEND is_objpack TO it_std_objpack.
    
      BREAK-POINT.
    *---------------------------------
    *loop for selecting the data into contents bin//// Excel.
      CONCATENATE 'SRNO' 'ASN no:' 'PARTNO' 'PART DESCRIPTION'
                  'QUANTITY' 'UNIT' INTO is_cntbin
      SEPARATED BY con_tab.
    
      CONCATENATE con_cret is_cntbin INTO is_cntbin.
      APPEND is_cntbin TO it_std_cntbin.
    
      LOOP AT it_std_items INTO is_items.
    
        sum_srno = sum_srno + 1.
    
        wrk_menge = is_items-menge.
        wrk_srno  = sum_srno.
    
        CONCATENATE wrk_srno is_items-asno is_items-matnr is_items-maktx
        wrk_menge is_items-meins
        INTO is_cntbin SEPARATED BY con_tab.
    
        CONCATENATE con_cret is_cntbin INTO is_cntbin.
        APPEND is_cntbin TO it_std_cntbin.
      ENDLOOP.
    
    *To be implemented later
    
    *
    *  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.
    *    CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
    *    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
    
    *--------------------------------
    
    
    
    
    
    
    
      DESCRIBE TABLE it_std_cntbin LINES wrk_lines.
    
      READ TABLE it_std_cntbin INTO is_cntbin INDEX wrk_lines.
    
      is_objpack-doc_size   = ( wrk_lines - 1 ) * 255 +
                               STRLEN( is_cntbin ).
    
    
      is_objpack-transf_bin = 'X'.
      is_objpack-head_start = 1.
      is_objpack-head_num   = 0.
      is_objpack-body_start = 1.
      is_objpack-body_num   = wrk_lines.
      is_objpack-doc_type   = 'XLS'.
    
      is_objpack-obj_name   = 'Document File'.
      is_objpack-obj_descr  = 'Document File'.
    
      APPEND is_objpack TO it_std_objpack.
    
    
    
    *Start of testing code
      IF sy-uname = 'DEVELOPER'.
    
        is_rcvlst-receiver = sy-uname.
        is_rcvlst-rec_type = 'B'.
        is_rcvlst-express  = 'X'.
    
        APPEND is_rcvlst TO it_std_rcvlst.
    
        CLEAR is_rcvlst.
    
      ENDIF.
    *End of testing code
    
    
    
    *Creating the recepient list
      is_rcvlst-receiver = 'abc@xyz.co.in'.
      is_rcvlst-rec_type = 'U'.
      is_rcvlst-express  = 'X'.
      is_rcvlst-com_type = 'INT'.
      APPEND is_rcvlst TO it_std_rcvlst.
    
    
      is_rcvlst-receiver = 'xyz@abc.com'.
      is_rcvlst-copy     = 'X'.
      is_rcvlst-rec_type = 'U'.
      is_rcvlst-express  = 'X'.
      is_rcvlst-com_type = 'INT'.
      APPEND is_rcvlst TO it_std_rcvlst.
    
    
    
    
    
    
      BREAK-POINT.
    
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data                    = is_docdata
       put_in_outbox                    = 'X'
       commit_work                      = 'X'
    * IMPORTING
    *   SENT_TO_ALL                      =
    *   NEW_OBJECT_ID                    =
        TABLES
          packing_list                     = it_std_objpack
    *   OBJECT_HEADER                    =
       contents_bin                     = it_std_cntbin
       contents_txt                     = it_std_objtxt
    *   CONTENTS_HEX                     =
    *   OBJECT_PARA                      =
    *   OBJECT_PARB                      =
          receivers                        = it_std_rcvlst
    * 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
                .
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    
      COMMIT WORK.
    
    

    Add comment
    10|10000 characters needed characters exceeded