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: 

SO_NEW_DOCUMENT_SEND_API1 multiple recipients

Former Member
0 Kudos

Hi,

I am using SO_NEW_DOCUMENT_SEND_API1 and it is working fine for me if there is one recipient.

Now I want to send the email to more than one recipient, so I just added the additional recipients into the table LT_MAILRECIPIENTS.


LT_MAILRECIPIENTS-REC_TYPE  = 'U'.
LT_MAILRECIPIENTS-RECEIVER = 'email1address'.
APPEND LT_MAILRECIPIENTS .
LT_MAILRECIPIENTS-RECEIVER = 'email2address'.
APPEND LT_MAILRECIPIENTS .
CLEAR LT_MAILRECIPIENTS.

Now if I call the function, it will only send to the first recipient in the table!

I tried to do a loop at LT_MAILRECIPIENTS and then call the function. Then it will send to all of them, but in the above case, every recipient will receive 2 emails instead of only 1.


CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
      EXPORTING
        DOCUMENT_DATA              = LT_MAILSUBJECT
      TABLES
        OBJECT_CONTENT             = LT_MAILTXT
        RECEIVERS                  = LT_MAILRECIPIENTS
      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 EQ 0.
      COMMIT WORK.

Any suggestions how I can send the email to all recipients in my table?

Thanks

Anne

16 REPLIES 16

Former Member
0 Kudos

Go through this already available program on Wiki carefully, i hope it will help you solve your problem.

[http://wiki.sdn.sap.com/wiki/display/Snippets/SendMultipleAttachmentsofSpoolwithE-mail]

Regards

Abhii

kesavadas_thekkillath
Active Contributor
0 Kudos

Your code seems to be fine.

How is LT_MAILRECIPIENTS declared ?

0 Kudos

Hi,

this is how LT_MAILRECIPIENTS is declared:

DATA: LT_MAILRECIPIENTS TYPE STANDARD TABLE OF SOMLREC90 WITH HEADER

LINE.

thanks

Anne

0 Kudos

try this..


data: LT_MAILRECIPIENTS type standard table of SOMLRECI1.

or 

DATA: LT_MAILRECIPIENTS TYPE STANDARD TABLE OF SOMLREC90 . "WITH HEADERLINE.

0 Kudos

Hi,

I tried the following, but it didn't help.


data: LT_MAILRECIPIENTS type standard table of SOMLRECI1 WITH HEADER
LINE.

I just realized that I forgot to copy the last 2 lines of my function call.


* Send Mail
    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
      EXPORTING
        DOCUMENT_DATA              = LT_MAILSUBJECT
      TABLES
        OBJECT_CONTENT             = LT_MAILTXT
        RECEIVERS                  = LT_MAILRECIPIENTS
      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 EQ 0.
      COMMIT WORK.

*   Push mail out from SAP outbox
      SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.
    ENDIF.

Can it have something to do with the line?

SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.

thanks

Anne

0 Kudos
data: LT_MAILRECIPIENTS type standard table of SOMLRECI1. " WITH HEADER LINE.

* Send Mail
    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
      EXPORTING
        DOCUMENT_DATA              = LT_MAILSUBJECT
      TABLES
        OBJECT_CONTENT             = LT_MAILTXT
        RECEIVERS                  = LT_MAILRECIPIENTS
      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 EQ 0.
      COMMIT WORK.
 
*   Push mail out from SAP outbox
      SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.
    ENDIF.

or

2. If you declaring internal table with header line, then pass LT_MAILRECIPIENTS[] to FM as Keshav mentioned.

data: LT_MAILRECIPIENTS type standard table of SOMLRECI1 WITH HEADER LINE.
* Send Mail
    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
      EXPORTING
        DOCUMENT_DATA              = LT_MAILSUBJECT
      TABLES
        OBJECT_CONTENT             = LT_MAILTXT
        RECEIVERS                  = LT_MAILRECIPIENTS[]. "LT_MAILRECIPIENTS
      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 EQ 0.
      COMMIT WORK.
 
*   Push mail out from SAP outbox
      SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.
    ENDIF.

0 Kudos

Hi gvsastry,

I tried both of your options.

For the first, I cannot activate the code, I get:

"LT_MAILRECIPIENTS" is a table without a header line and therefore has no component called "REC_TYPE".

I can activate the 2nd option, but here I only get one email instead of two.

Thanks

Anne

0 Kudos

>

> Hi gvsastry,

>

> I tried both of your options.

>

> For the first, I cannot activate the code, I get:

> "LT_MAILRECIPIENTS" is a table without a header line and therefore has no component called "REC_TYPE".

DATA: LS_MAILRECIPIENTS TYPE SOMLRECI1.
   APPEND LS_MAILRECIPIENTS TO LT_MAILRECIPIENTS.

>

> I can activate the 2nd option, but here I only get one email instead of two.

>

> Thanks

> Anne

I would suggest you debug and see how many entries are present in lt_mailrecipients when you are passing to FM.

0 Kudos

Hi,

I just debugged and there are two entries in LT[].

The strange thing for me is, when I do the following, everyone in the list gets 2 emails. So it is behaving actually correct with the loop. Of course I don't want 2 emails, but it seems to send to EVERYONE in the list (vs. just for the first one) for each loop. Does that make sense?


LOOP at LT_MAILRECIPIENTS.
    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
      EXPORTING
        DOCUMENT_DATA              = LT_MAILSUBJECT
      TABLES
        OBJECT_CONTENT             = LT_MAILTXT
        RECEIVERS                  = LT_MAILRECIPIENTS
      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 EQ 0.
      COMMIT WORK.

*   Push mail out from SAP outbox
      SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.
    ENDIF.
endloop.

0 Kudos

Don't call FM in loop.

0 Kudos

Ok. Do you have any other suggestions how I could get it to work?

Thanks

Anne

0 Kudos

Don't call FM in loop.

didnt notice it !!!! Gr8.

GauthamV
Active Contributor
0 Kudos

Try this code.


LT_MAILRECIPIENTS-REC_TYPE  = 'U'.
LT_MAILRECIPIENTS-RECEIVER = 'email1address'.
APPEND LT_MAILRECIPIENTS .

LT_MAILRECIPIENTS-REC_TYPE  = 'U'.
LT_MAILRECIPIENTS-RECEIVER = 'email2address'.
APPEND LT_MAILRECIPIENTS .


CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
      EXPORTING
        DOCUMENT_DATA              = LT_MAILSUBJECT
      TABLES
        OBJECT_CONTENT             = LT_MAILTXT
        RECEIVERS                  = LT_MAILRECIPIENTS
      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 EQ 0.
      COMMIT WORK.
    ENDIF.

JerryWang
Advisor
Advisor
0 Kudos

Hello Anne,

you can refer to this link, it is talking about the same topic as yours.

Best Regards,

Jerry

kesavadas_thekkillath
Active Contributor
0 Kudos

Just a try,

pass it like

RECEIVERS = LT_MAILRECIPIENTS[].

Its time to get rid of header lines

Instead of this fm i suggest you to use the BCS classes available. This fm doesnt support certain code pages.

For BCS classes example sin SE38 just search for BCSEXAMPLE

@gautham - I dont see any difference in OP's code and yours

Former Member
0 Kudos

In debug, look at the contents of your recipient table and be sure it is correct. See SAP Note 609696 for update documentation and working code, should you decide to continue to use this out-of-date method for email.