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 multiple user

Former Member
0 Likes
1,687

All experts:

I want to send an email to multiple user, I use the FM:SO_NEW_DOCUMENT_SEND_API1,

this FM can to mutiple user's email address ,but it can not re-set the email sender.

another FM is: EFG_GEN_SEND_EMAIL, this FM can re-set the email sender and email receiver, but this only can send one email to one receiver.

My question is, can anyone tell me how to send email to mutiple user,

e.g.: sender: abc/at/abc.com

receiver 1 cdg/at/abc.com

receiver 2 dd/at/hotmail.com

I want to send this email to both them at a time. and i can dynamic set the email sender.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,167

HI,

MAke the changes according to:

Add the recipients email address

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = Emailid1

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

t_receivers-receiver = emailid2

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

t_receivers-receiver = emailid3

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.

Regards,

Shiva

All experts:

I want to send an email to multiple user, I use the FM:SO_NEW_DOCUMENT_SEND_API1,

this FM can to mutiple user's email address ,but it can not re-set the email sender.

another FM is: EFG_GEN_SEND_EMAIL, this FM can re-set the email sender and email receiver, but this only can send one email to one receiver.

My question is, can anyone tell me how to send email to mutiple user,

e.g.: sender: abc/at/abc.com

receiver 1 cdg/at/abc.com

receiver 2 dd/at/hotmail.com

I want to send this email to both them at a time. and i can dynamic set the email sender.

Thanks in advance.

3 REPLIES 3
Read only

Former Member
0 Likes
1,167

You can very well use the same FM to send the email to multiple users.

FM : SO_NEW_DOCUMENT_SEND_API1

Tables parameter has receiver RECEIVERS.

append the emails that you want to send to this internal table and pass it to the FM

wa_receiver-rec_type = 'U".

wa_receiver-receiver = 'email1'.

APPEND wa_receiver TO t_receiver.

t_receiver TYPE STANDARD TABLE OF somlreci1

reward if u find this useful

Read only

Former Member
0 Likes
1,168

HI,

MAke the changes according to:

Add the recipients email address

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = Emailid1

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

t_receivers-receiver = emailid2

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

t_receivers-receiver = emailid3

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.

Regards,

Shiva

Read only

Former Member
0 Likes
1,167

Hi,

It is a good practice to write a function to send email and use this function as much as you want.

Please create the following function exactly,

it will help you:

You see imports and exports of this function:

TO1 through TO3 is the mail adresses you can pass. You can use just one of them or all of them.

And you can use the BODY STRUCTURE TLINE OPTIONAL

as the contents of the email.

Hope helps.

FUNCTION Z_PA_SENDMAIL.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(TO1) LIKE  ADR6-SMTP_ADDR
*"     VALUE(TO2) LIKE  ADR6-SMTP_ADDR OPTIONAL
*"     VALUE(TO3) LIKE  ADR6-SMTP_ADDR OPTIONAL
*"     VALUE(SUBJECT) LIKE  TZV51-XBRIEF
*"     VALUE(ATT_TYPE) LIKE  SOOD-OBJTP OPTIONAL
*"     VALUE(ATT_NAME) LIKE  SOOD-OBJNAM OPTIONAL
*"     VALUE(ATT_DESC) LIKE  SOOD-OBJDES OPTIONAL
*"     VALUE(NOTIF_DEL) LIKE  SOMLRECI1-NOTIF_DEL OPTIONAL
*"     VALUE(NOTIF_READ) LIKE  SOMLRECI1-NOTIF_READ OPTIONAL
*"     VALUE(NOTIF_NDEL) LIKE  SOMLRECI1-NOTIF_NDEL DEFAULT 'X'
*"     VALUE(SEND_AS) LIKE  SOEXTRECI1-RECEIVER DEFAULT SPACE
*"  EXPORTING
*"     VALUE(SENT_FLAG) LIKE  SOPR-FLAG1
*"  TABLES
*"      BODY STRUCTURE  TLINE OPTIONAL
*"      ATTCH STRUCTURE  SOLISTI1 OPTIONAL
*"  EXCEPTIONS
*"      TOO_MANY_RECEIVERS
*"      DOCUMENT_NOT_SENT
*"      OPERATION_NO_AUTHORIZATION
*"----------------------------------------------------------------------

 data: doc_chng like sodocchgi1.
 data : objpack like sopcklsti1   occurs 10 with header line,
        objhead like solisti1     occurs 10 with header line,
        objbin  like solisti1     occurs 10 with header line,
        objtxt  like solisti1     occurs 10 with header line,
        reclist like somlreci1    occurs 10 with header line.
 data: tab_lines like sy-tabix.
 data: sent_to_all like sonv-flag.

 objtxt[] = body[].
 objbin[] = attch[].

 doc_chng-obj_name  = 'Mail'.
 doc_chng-obj_descr = subject.

* Creation of the entry for the compressed document
 describe table objtxt lines tab_lines.
 clear objpack-transf_bin.
 objpack-head_start = 1.
 objpack-head_num = 0.
 objpack-body_start = 1.
 objpack-body_num = tab_lines.

 read table objtxt index tab_lines.
 objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
 doc_chng-doc_size = doc_chng-doc_size + objpack-doc_size.
 objpack-doc_type = 'RAW'.
 objpack-obj_name  = 'Body'.
 objpack-obj_descr = subject.
 append objpack.

 describe table objbin lines tab_lines.
 if tab_lines > 0.
  objpack-transf_bin = 'X'.
  objpack-head_start = 1.
  objpack-head_num = 0.
  objpack-body_start = 1.
  objpack-body_num = tab_lines.

  read table objbin index tab_lines.
  objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objbin ).
  doc_chng-doc_size = doc_chng-doc_size + objpack-doc_size.
  objpack-doc_type = att_type.
  objpack-obj_name = att_name.
  objpack-obj_descr = att_desc.
  append objpack.
 endif.

 reclist-rec_type  = 'U'.
 reclist-notif_del = NOTIF_DEL.
 reclist-notif_read = NOTIF_READ.
 reclist-notif_ndel = NOTIF_NDEL.
 reclist-receiver  = to1.
 append reclist.
 if not to2 is initial.
  reclist-receiver  = to2.
  append reclist.
 endif.
 if not to3 is initial.
  reclist-receiver  = to3.
  append reclist.
 endif.

 delete reclist where receiver eq space.

  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
       exporting
            document_data              = doc_chng
            put_in_outbox              = ' '
            commit_work                = 'X'
*            SENDER_ADDRESS             = send_as
       importing
            sent_to_all                = sent_flag
       tables
            packing_list               = objpack
            object_header              = objhead
            contents_bin               = objbin
            contents_txt               = objtxt
            receivers                  = reclist
       exceptions
            too_many_receivers         = 1
            document_not_sent          = 2
            operation_no_authorization = 4
            others                     = 99.

  case sy-subrc.
   when 0.
* SUCCESS
   when 1.
    raise TOO_MANY_RECEIVERS.
   when 2.
    raise DOCUMENT_NOT_SENT.
   when 4.
    raise OPERATION_NO_AUTHORIZATION.
   when others.
    raise OTHERS.
  endcase.

ENDFUNCTION.