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

Send email to distribution list using OOP...

aris_hidalgo
Contributor
0 Likes
1,025

Hello Experts,

I currently have a requirement to send email(w/o attachment) to a distribution list or specific user. I have searched the forum and it doesnt suit my requirement as the examples gives only how to send email to specific user/s. Any inputs would be appreciated.

Thank you guys and take care!

1 ACCEPTED SOLUTION
Read only

rainer_hbenthal
Active Contributor
0 Likes
823

If you have an exchange based distribution list just send the mail to it. Otherwise, concatenate all users separated with semicolon in to, cc, or bcc field.

If you have an exchange based distribution list just send the mail to it. Otherwise, concatenate all users separated with semicolon in to, cc, or bcc field.

3 REPLIES 3
Read only

rainer_hbenthal
Active Contributor
0 Likes
824

If you have an exchange based distribution list just send the mail to it. Otherwise, concatenate all users separated with semicolon in to, cc, or bcc field.

Read only

Former Member
0 Likes
823

Hi,

You can use FM ''SO_DLI_READ_API1'' to find all the mail ids in the DL. then use the individual ids to send mail.

Thanks,

renjith.

Read only

Former Member
0 Likes
823

Hi ,

For sending mail with attachments in multiple sheets of an excel document please see the

sample code below:


REPORT  ZBC_ITAB_TO_EXCEL_NEW                   .

CLASS: cl_abap_char_utilities DEFINITION LOAD.

DATA: docdata LIKE sodocchgi1,
      objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
      objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
      objbin1 LIKE solisti1 OCCURS 10 WITH HEADER LINE,
      objbin2 LIKE solisti1 OCCURS 10 WITH HEADER LINE,
      objbin_final LIKE solisti1 OCCURS 10 WITH HEADER LINE,
      reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
      tab_lines TYPE sy-tabix.

DATA: gd_sender_type LIKE soextreci1-adr_typ.

DATA: c_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
      c_ret TYPE c VALUE cl_abap_char_utilities=>cr_lf.

DATA: c_dev TYPE sy-sysid.

DATA: BEGIN OF i_data OCCURS 0,
      a(20),
      b(20),
      END OF i_data.

DATA: BEGIN OF st,
      f1(2) TYPE c,
      f2(2) TYPE n,
      END OF st.

DATA: itab1 LIKE TABLE OF st WITH HEADER LINE,
      itab2 LIKE TABLE OF st WITH HEADER LINE.


DATA: n TYPE i.

PARAMETER: p_email1 LIKE somlreci1-receiver
                    ,
           p_sender LIKE somlreci1-receiver.

START-OF-SELECTION.

  itab1-f1 = 'AA'. itab1-f2 = '01'. APPEND itab1.
  itab1-f1 = 'BB'. itab1-f2 = '02'. APPEND itab1.
  itab1-f1 = 'CC'. itab1-f2 = '03'. APPEND itab1.

  itab2-f1 = 'ZZ'. itab2-f2 = '26'. APPEND itab2.
  itab2-f1 = 'YY'. itab2-f2 = '25'. APPEND itab2.

  LOOP AT itab1.
    CONCATENATE itab1-f1 itab1-f2 INTO objbin1 separated BY c_tab.
    CONCATENATE c_ret objbin1 INTO objbin1.
    APPEND objbin1.
  ENDLOOP.

  LOOP AT itab2.
    CONCATENATE itab2-f1 itab2-f2 INTO objbin2 separated BY c_tab.
    CONCATENATE c_ret objbin2 INTO objbin2.
    APPEND objbin2.
  ENDLOOP.

  LOOP AT objbin1.
    MOVE objbin1-line TO objbin_final-line.
    APPEND objbin_final.
  ENDLOOP.

  LOOP AT objbin2.
    MOVE objbin2-line TO objbin_final-line.
    APPEND objbin_final.
  ENDLOOP.

  PERFORM process_email.
  c_dev = sy-sysid.

  IF sy-sysid = c_dev.
    wait up to 5 seconds.
    SUBMIT rsconn01 WITH mode = 'INT'
    WITH output = 'X'
    AND RETURN.
  ENDIF.

  IF sy-subrc = 0.
    WRITE: / 'Email succesfilly delivered'.
  ELSE.
    WRITE: / 'failure'.
  ENDIF.

*&--------------------------------------------------------------------*
*&      Form  process_email
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM process_email.

  IF p_sender EQ space.
    gd_sender_type = space.
  ELSE.
    gd_sender_type = 'INT'.
  ENDIF.

*Body
  docdata-obj_name = 'Mail_Excel_File'.
  docdata-obj_descr = 'Excel file attachment'.
  objtxt = 'Attached is the sample Excel file'.
  APPEND objtxt.
  DESCRIBE TABLE objtxt LINES tab_lines.
  READ TABLE objtxt INDEX tab_lines.
  docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).

  CLEAR objpack-transf_bin.
  objpack-head_start = 1.
  objpack-head_num = 0.
  objpack-body_start = 1.
  objpack-body_num = tab_lines.
  objpack-doc_type = 'RAW'.
  APPEND objpack.

*Attachment
  n = 1.

  DESCRIBE TABLE objbin1 LINES tab_lines.
  objpack-doc_size = tab_lines * 255.
  objpack-transf_bin = 'X'.
  objpack-head_start = 1.
  objpack-head_num = 1.
  objpack-body_start = n.
  objpack-body_num = tab_lines.
  objpack-doc_type = 'XLS'.
  docdata-obj_name = 'Excel_File_Attachment1'.
  objpack-obj_descr = 'Excel File Attachment1'.
  APPEND objpack.

  n = n + tab_lines.

  DESCRIBE TABLE objbin2 LINES tab_lines.
  objpack-doc_size = tab_lines * 255.
  objpack-transf_bin = 'X'.
  objpack-head_start = 1.
  objpack-head_num = 1.
  objpack-body_start = n.
  objpack-body_num = tab_lines.
  objpack-doc_type = 'XLS'.
  docdata-obj_name = 'Excel_File_Attachment2'.
  objpack-obj_descr = 'Excel File Attachment2'.
  APPEND objpack.


*Create the list of recipients
  reclist-receiver = p_email1.
  reclist-rec_type = 'U'.
  reclist-express = 'X'.
  APPEND reclist.                 "For sending mail to multiple ids append this internal table with your reqd ids


*Send the e-mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = docdata
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = objpack
      contents_bin               = objbin_final
      contents_txt               = objtxt
      receivers                  = reclist
    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.

  COMMIT WORK.
ENDFORM.                    "process_email

Hope it helps,

Regards

Mansi

Edited by: MANSI ASNANI on Oct 13, 2009 7:56 AM