Application Development 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: 

Send Email to list of users

Former Member
0 Kudos

Hi All,

I need to develop a program which is a report but need to send the report output in email to the customers.Till report output i could develop the program but i want to know how to send this report output in email to the list of user.Can anybody help me on this?Example code will be more useful.

Thanks

Sai

5 REPLIES 5

Former Member
0 Kudos

Hi,

Create a Distribution list using SO23 and add Users whom to recieve messages.

Use below function module to send the mail.

SO_NEW_DOCUMENT_SEND_API1

Reward points if it is helpful

Regards,

Ashok

Former Member
0 Kudos

Hi,

refer this...

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.

Also Thing is that there is a function module for the same.

Function module name is 'MESSAGE_SEND_AS_MAIL'. I am suggesting this function module bcoz I understood that you want to send a message that you get in your program as mail to the receipient.

Using this FM is simple: Just pass the MESG - ID and MESG NO to this Function module. Then create an Internal table of structure 'SOMLRECI1' and populate that Internal table with the receipient info and pass it to the FM.

Please refer to the link below :

http://www.sapdev.co.uk/reporting/email/email_sapmail.htm

Reward Points if found helpfull..

Cheers,

Chandra Sekhar.

Former Member
0 Kudos

Hi,

create a distribution list first in SO23...

Schedule the report as background job and in the

spool-reciepient give the distribution list name........

once the job is competed execute 'RSCONN01' report in se38......the list output ll be automatically sent as mail....

Cheers,

Will.

Former Member
0 Kudos

hi

good

You can use following FM's

call function to send email

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = docdata

document_type = 'RAW'

commit_work = 'X'

TABLES

object_header = t_objhead

object_content = t_objtxt

receivers = t_receiver

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.

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

also if you want to attach any file with the mail u can use following FM

Sending the document

IF NOT l_t_reclist[] IS INITIAL.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = l_doc_chng

commit_work = 'X'

TABLES

packing_list = l_t_objpack

object_header = l_t_objhead

contents_bin = l_t_objbin

contents_txt = l_t_objtxt

receivers = l_t_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

ENDIF.

hope this helps..

thanks

mrutyun^

Former Member
0 Kudos

Below code can help as reference as well:


PARAMETERS: p_mail TYPE ad_smtpadr OBLIGATORY.
 
DATA: i_mara TYPE STANDARD TABLE OF mara.  " MARA Entries
DATA: l_text TYPE char255.  " Text
DATA: l_lines TYPE i,
      l_size            TYPE           sood-objlen.
" Size of Attachment
 
 
* Mail related
DATA: i_content         TYPE   soli_tab, " Mail content
      i_attach          TYPE   soli_tab. " Attachment
 
DATA: l_send_request    TYPE REF TO    cl_bcs,
                                            " E-Mail Send Request
      l_document        TYPE REF TO    cl_document_bcs,
                                            " E-Mail Attachment
      l_recipient       TYPE REF TO    if_recipient_bcs,
                                            " Distribution List
      l_sender          TYPE REF TO    if_sender_bcs,
                                            " Address of Sender
      l_uname           TYPE           salrtdrcpt,
                                            " Sender Name(SY-UNAME)
      l_bcs_exception   TYPE REF TO    cx_document_bcs,
                                            " BCS Exception
      l_addr_exception  TYPE REF TO    cx_address_bcs,
                                            " Address Exception
      l_send_exception  TYPE REF TO    cx_send_req_bcs.
" E-Mail sending Exception
 
.
 
*
*Constants------------------------------------------------------------*
CONSTANTS: c_tab(1) TYPE c VALUE
               cl_abap_char_utilities=>horizontal_tab,
                                     " Tab Character
 
           c_cr(1)  TYPE c VALUE cl_abap_char_utilities=>cr_lf,
                                     " Line Feed for End-Of_line
 
           c_ext    TYPE soodk-objtp VALUE 'XLS'. " XLS Extension
 
START-OF-SELECTION.
 
  SELECT * FROM mara INTO TABLE i_mara UP TO 20 ROWS.
 
* Preparing body of the Mail
  MOVE 'Mail Body' TO l_text.
  APPEND l_text TO i_content.
 
* Preparing contents of attachment with Change Log
  PERFORM prepare_attachment.
 
* Creates persistent send request
  TRY.
      l_send_request = cl_bcs=>create_persistent( ).
 
* Creating Document
      l_document = cl_document_bcs=>create_document(
                                    i_type  = 'RAW'
                                    i_text  = i_content[]
                                    i_subject = 'Material Details' ).
 
      DESCRIBE TABLE i_mara LINES l_lines.
* Size to multiplied by 2 for UNICODE enabled systems
      l_size = l_lines * 2 * 255.
 
* Adding Attachment
      CALL METHOD l_document->add_attachment
        EXPORTING
          i_attachment_type    = c_ext
          i_attachment_size    = l_size
          i_attachment_subject = 'Material Details'
          i_att_content_text   = i_attach[].
 
* Add document to send request
      CALL METHOD l_send_request->set_document( l_document ).
 
* Get Sender Object
      l_uname = sy-uname.
 
      l_sender = cl_sapuser_bcs=>create( l_uname ).
 
      CALL METHOD l_send_request->set_sender
        EXPORTING
          i_sender = l_sender.
 
* E-Mail
      TRANSLATE p_mail TO LOWER CASE.
 
    l_recipient = cl_cam_address_bcs=>create_internet_address( p_mail )
.
 
      CALL METHOD l_send_request->add_recipient
        EXPORTING
          i_recipient  = l_recipient
          i_express    = 'U'
          i_copy       = ' '
          i_blind_copy = ' '
          i_no_forward = ' '.
 
 
*Trigger E-Mail immediately
      l_send_request->set_send_immediately( 'X' ).
 
      CALL METHOD l_send_request->send( ).
 
      COMMIT WORK.
 
    CATCH cx_document_bcs INTO l_bcs_exception.
 
    CATCH cx_send_req_bcs INTO l_send_exception.
 
    CATCH cx_address_bcs  INTO l_addr_exception.
 
  ENDTRY.
 
 
*&---------------------------------------------------------------------
*
*&      Form  PREPARE_ATTACHMENT
*&---------------------------------------------------------------------
*
FORM prepare_attachment .
 
  FIELD-SYMBOLS: <lfs_table>,    " Internal table structure
                 <lfs_con>.      " Field Content
  DATA: l_text TYPE char1024.     " Text content for mail attachment
  DATA: l_con(50) TYPE c.        " Field Content in character format
 
* Columns to be tab delimeted
  LOOP AT i_mara ASSIGNING <lfs_table>.
    DO.
      ASSIGN COMPONENT sy-index OF STRUCTURE <lfs_table>
             TO <lfs_con>.
      IF sy-subrc NE 0.
        CONCATENATE c_cr l_text INTO l_text.
        APPEND l_text TO i_attach.
        EXIT.
      ELSE.
        CLEAR: l_con.
        MOVE <lfs_con> TO l_con.
        CONDENSE l_con.
        IF sy-index = 1.
          CLEAR: l_text.
          MOVE l_con TO l_text.
        ELSE.
          CONCATENATE l_text l_con INTO l_text
             SEPARATED BY c_tab.
        ENDIF.
      ENDIF.
    ENDDO.
  ENDLOOP.
 
ENDFORM.                    " PREPARE_ATTACHMENT

Regards

Eswar