Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Email with attachment

Former Member
0 Likes
927

Hi Friends,

I am trying to send a mail with an attachment. I am getting the sy-subrc value as 6. i.e. x_error. What does this mean ? How to correct this ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
800

Hi,

Try this code. I dont know what is that error.

*&---------------------------------------------------------------------*
*& Report  ZEMAIL_ATTACH                                               *
*&                                                                     *
*&---------------------------------------------------------------------*
*& Example of sending external email via SAPCONNECT                    *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  ZEMAIL_ATTACH                   .
TABLES: ekko.

PARAMETERS: p_email   TYPE somlreci1-receiver
                                  DEFAULT 'Your Email address'.

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.
  CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode
             con_tab TYPE x 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.
    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


*&---------------------------------------------------------------------*
*&      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

Thanks

Vikranth

Hi Friends,

I am trying to send a mail with an attachment. I am getting the sy-subrc value as 6. i.e. x_error. What does this mean ? How to correct this ?

5 REPLIES 5
Read only

Former Member
0 Likes
800

This message was moderated.

Read only

Former Member
0 Likes
800

It means your email is sent with some errors.

the following threads will help you

/thread/98781 [original link is broken]



Sending mail with attachment 
* 
* This program will allowed you to send email with attachment. 
* First, specify the attachment file from your local hardisk and execute. 
* Next, specify the sender email address and click the send button. 
* 

 
* 
report y_cr17_mail. 

data method1 like sy-ucomm. 
data g_user like soudnamei1. 
data g_user_data like soudatai1. 
data g_owner like soud-usrnam. 
data g_receipients like soos1 occurs 0 with header line. 
data g_document like sood4 . 
data g_header like sood2. 
data g_folmam like sofm2. 
data g_objcnt like soli occurs 0 with header line. 
data g_objhead like soli occurs 0 with header line. 
data g_objpara  like selc occurs 0 with header line. 
data g_objparb  like soop1 occurs 0 with header line. 
data g_attachments like sood5 occurs 0 with header line. 
data g_references like soxrl occurs 0 with header line. 

data g_authority like sofa-usracc. 
data g_ref_document like sood4. 
data g_new_parent like soodk. 
data: begin of g_files occurs 10 , 
  text(4096) type c, 
   end of g_files. 

data : fold_number(12) type c, 
       fold_yr(2) type c, 
       fold_type(3) type c. 

parameters ws_file(4096) type c default 'c:\debugger.txt'. 
* Can me any file fromyour pc ....either xls or word or ppt etc ... 
g_user-sapname = sy-uname. 
call function 'SO_USER_READ_API1' 
exporting 
   user                            = g_user 
*    PREPARE_FOR_FOLDER_ACCESS       = ' ' 
importing 
   user_data                       = g_user_data 
*  EXCEPTIONS 
*    USER_NOT_EXIST                  = 1 
*    PARAMETER_ERROR                 = 2 
*    X_ERROR                         = 3 
*    OTHERS                          = 4 
          . 
if sy-subrc <> 0. 
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO 
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
endif. 

fold_type = g_user_data-outboxfol+0(3). 
fold_yr = g_user_data-outboxfol+3(2). 
fold_number =  g_user_data-outboxfol+5(12). 
clear g_files. 

refresh : g_objcnt, 
  g_objhead, 
  g_objpara, 
  g_objparb, 
  g_receipients, 
  g_attachments, 
  g_references, 
  g_files. 

method1 = 'SAVE'. 
g_document-foltp  = fold_type. 
g_document-folyr   = fold_yr. 
g_document-folno   = fold_number. 
g_document-objtp   = g_user_data-object_typ. 
*g_document-OBJYR   = '27'. 
*g_document-OBJNO   = '000000002365'. 
*g_document-OBJNAM = 'MESSAGE'. 
g_document-objdes   = 'sap-img.com testing by program'. 
g_document-folrg   = 'O'. 
*g_document-okcode   = 'CHNG'. 
g_document-objlen = '0'. 
g_document-file_ext = 'TXT'. 

g_header-objdes =  'sap-img.com testing by program'. 
g_header-file_ext = 'TXT'. 

call function 'SO_DOCUMENT_REPOSITORY_MANAGER' 
  exporting 
    method             = method1 
   office_user        = sy-uname 
   ref_document       = g_ref_document 
   new_parent         =  g_new_parent 
importing 
   authority          =  g_authority 
tables 
   objcont            = g_objcnt 
   objhead            = g_objhead 
   objpara            = g_objpara 
   objparb            = g_objparb 
   recipients         = g_receipients 
   attachments        = g_attachments 
   references         = g_references 
   files              = g_files 
  changing 
    document           = g_document 
   header_data        = g_header 
*   FOLMEM_DATA        = 
*   RECEIVE_DATA       = 
          . 

* File from the pc to send... 
method1 = 'ATTCREATEFROMPC'. 

g_files-text = ws_file. 
append g_files. 

call function 'SO_DOCUMENT_REPOSITORY_MANAGER' 
  exporting 
    method             = method1 
   office_user        = g_owner 
   ref_document       = g_ref_document 
   new_parent         =  g_new_parent 
importing 
   authority          =  g_authority 
tables 
   objcont            = g_objcnt 
   objhead            = g_objhead 
   objpara            = g_objpara 
   objparb            = g_objparb 
   recipients         = g_receipients 
   attachments        = g_attachments 
   references         = g_references 
   files              = g_files 
  changing 
    document           = g_document 
   header_data        = g_header 
          . 

method1 = 'SEND'. 

g_receipients-recnam = 'MK085'. 
g_receipients-recesc = 'B'. 
g_receipients-sndex = 'X'. 
append  g_receipients. 
  

call function 'SO_DOCUMENT_REPOSITORY_MANAGER' 
  exporting 
    method             = method1 
   office_user        = g_owner 
   ref_document       = g_ref_document 
   new_parent         =  g_new_parent 
importing 
   authority          =  g_authority 
tables 
   objcont            = g_objcnt 
   objhead            = g_objhead 
   objpara            = g_objpara 
   objparb            = g_objparb 
   recipients         = g_receipients 
   attachments        = g_attachments 
   references         = g_references 
   files              = g_files 
  changing 
    document           = g_document 
   header_data        = g_header. 

*-- End of Program 

Read only

Former Member
0 Likes
800

Hi Manjunath,

Tyr to Pass same parameter to either FMs.

SO_DOCUMENT_SEND_API1 if used only change would be senders address.

Cheers

Mohinder Singh

Edited by: Mohinder Singh Chauhan on Jun 26, 2008 6:17 AM

Read only

Former Member
0 Likes
801

Hi,

Try this code. I dont know what is that error.

*&---------------------------------------------------------------------*
*& Report  ZEMAIL_ATTACH                                               *
*&                                                                     *
*&---------------------------------------------------------------------*
*& Example of sending external email via SAPCONNECT                    *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  ZEMAIL_ATTACH                   .
TABLES: ekko.

PARAMETERS: p_email   TYPE somlreci1-receiver
                                  DEFAULT 'Your Email address'.

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.
  CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode
             con_tab TYPE x 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.
    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


*&---------------------------------------------------------------------*
*&      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

Thanks

Vikranth

Read only

Former Member
0 Likes
800

Hi Manjunath,

Here is the below sample code for external mail.

<removed by moderator>


DATA: ld_mtitle LIKE sodocchgi1-obj_descr,
        ld_format TYPE  so_obj_tp ,
        ld_attdescription TYPE  so_obj_nam ,
        ld_attfilename TYPE  so_obj_des .
*        ld_receiver LIKE  sy-subrc.



  DATA:   it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
          it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
          w_cnt TYPE i,
          w_sent_all(1) TYPE c,                             "#EC NEEDED
          w_doc_data LIKE sodocchgi1.

  REFRESH it_receivers . CLEAR it_receivers .
  IF v_trip_send = 'X'.
    it_receivers-receiver = it_trip_dload-approver_email .
  ELSE .
    it_receivers-receiver = it_adv_dload-approver_email .
  ENDIF.
  it_receivers-rec_type = c_u .
  APPEND it_receivers. CLEAR it_receivers.

*  it_receivers-receiver = " paass email address .
  IF v_trip_send = 'X' .
    it_receivers-receiver = it_trip_dload-requester_email .
  ELSE .
    it_receivers-receiver = it_adv_dload-requester_email .
  ENDIF .
  it_receivers-rec_type = c_u .
  it_receivers-copy     = 'X' .
  APPEND it_receivers. CLEAR it_receivers.


  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attdescription      = p_attdescription.
  ld_attfilename         = p_filename.

* 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  = c_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   = c_saprpt.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = c_f.
  CLEAR it_attachment.
  REFRESH it_attachment.
  it_attachment[] = it_attach[].

* 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 = c_raw.
  APPEND it_packing_list.

* Create attachment notification
  it_packing_list-transf_bin = c_x.
  it_packing_list-head_start = 1.
  it_packing_list-head_num   = 1.
  it_packing_list-body_start = 1.

  DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.
  it_packing_list-doc_type   =  ld_format.
  it_packing_list-obj_descr  =  ld_attdescription.
  it_packing_list-obj_name   =  ld_attfilename.
  it_packing_list-doc_size   =  it_packing_list-body_num * 255.
  APPEND it_packing_list.


  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data = w_doc_data
      put_in_outbox = c_x
      commit_work   = c_x
    IMPORTING
      sent_to_all   = w_sent_all
    TABLES
      packing_list  = it_packing_list
      contents_bin  = it_attachment
      contents_txt  = it_message
      receivers     = it_receivers.


Edited by: Mike Pokraka on Aug 4, 2008 2:45 PM