cancel
Showing results for 
Search instead for 
Did you mean: 

Email invoice to multiple recipients

Former Member
0 Kudos

I need to email invoice to multiple recipients. I set nacha-medium = '5' with communication strategy = 'INT'. It works as expected but only send PDF invoice attachment to one recipient. I noticed that the include module RVADOPFO call func module 'CONVERT_COMM_TYPE_DATA' to pass the recipient address.

The invoice will be sent to recipient in the close_form FM, using the email address passed in the open_form FM. If I want to send to multiple recipients or add CC or BCC recipient, does anyone know how.

I think can copy the FM 'CONVERT_COMM_TYPE_DATA' to a Zxx FM but I do not know how to modify in the part that create the recipient since I am not familiar with OO method. This is the code I saw in that FM.

-


      • Internet Mail ***

WHEN c_comm_smtp.

  • get title for mail

pe_itcpo-tdtitle = pi_snast-tdcovtitle.

  • create recipient

swc_create_object l_recipient 'RECIPIENT' space.

swc_set_element lt_container 'AddressString'

pi_comm_values-adsmtp-smtp_addr.

swc_set_element lt_container 'TypeID' 'U'.

swc_call_method l_recipient 'CreateAddress' lt_container.

IF sy-subrc NE 0.

MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

RAISING recipient_creation_failed.

ENDIF.

  • set 'deliver' attribute

swc_clear_container lt_container.

swc_set_element lt_container 'Deliver' l_deliver.

swc_call_method l_recipient 'SetDeliver' lt_container.

  • set 'not deliver' attribute

swc_clear_container lt_container.

swc_set_element lt_container 'NotDeliver' l_not_deli.

swc_call_method l_recipient 'SetNotDeliver' lt_container.

  • set 'mailstatus' attribute

swc_clear_container lt_container.

swc_set_element lt_container 'StatusInfoByMail' l_mailstatus.

swc_call_method l_recipient 'SetStatusInfoByMail' lt_container.

    • ***********start of modification***********************

    • switch off delivery notification "<--INSERT

  • swc_clear_container lt_container. "<--INSERT

  • swc_set_element lt_container 'Deliver' space. "<--INSERT

  • swc_call_method l_recipient 'SetDeliver' lt_container."<--INSERT

  • swc_call_method l_recipient 'Save' lt_container. "<--INSERT

    • ***********end of modification***********************

swc_object_to_persistent l_recipient pe_mail_recipient.

.....

I use Sapscript not SmartForm. Thanks for your help.

I know that we can create OTF data and send email using table OTF data but I want to use the SAP standard that will email when we close the form. Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Any one have any idea?

Former Member
0 Kudos

Problem solved. Thanks

Former Member
0 Kudos

Hi Akinosora,

I also have the same problem, Could you please let me know your solution?

Thank you,

Surya

Former Member
0 Kudos

Sorry I was out sick. Instead of using SAP standard processing, I just create OTF data, convert to PDF format and email to multiple recipients using class cl_bcs or create distribution list using class cl_distributionlist_bcs

-


add recipient (e-mail address) -


  • create recipient

recipient = cl_cam_address_bcs=>create_internet_address(

'xxx@yahoo.com' ).

  • add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = 'X'.

  • add distribution list set up from SAPOffice to send request

Recipient = cl_distributionlist_bcs=>getu_persistent( i_dliname = ‘DLIST’

i_private = ‘X’ ).

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = 'X'.

  • ---------- send document ---------------------------------------

CALL METHOD send_request->send(

EXPORTING

i_with_error_screen = 'X'

RECEIVING

result = sent_to_all ).

IF sent_to_all = 'X'.

WRITE text-003.

ENDIF.

COMMIT WORK.

  • -----------------------------------------------------------

  • * exception handling

  • -----------------------------------------------------------

catch cx_bcs into bcs_exception.

write: / 'Failed to send email.'(001).

write: / 'BCS_Exception error type:'(002),

bcs_exception->error_type.

exit.

endtry.

Former Member
0 Kudos

Thanks for your response and time. I know this method. I was trying to use SAP standard processing. One of our SDN member sent me the code. Even I have no option except this.

Thank you,

Surya.

Former Member
0 Kudos

I was trying to use SAP standard processing also by setting output medium 5 but I could not send to multiple recipients and cannot add email body. My guess is that it might have some user exit during the close_form because that is where the email is sent or print or archive, but I do not know how and where to add body of email text.

Former Member
0 Kudos

Hi Akinosora,

You can add some email body text through SAP standard processing by adding text in "Mail title and texts" for an output type. You can give document title also there.

Only thing I could not able to do with SAP standard process is that not been able to send email to multiple recipients and not able to pass sender as regualr email address. The FM CONVERT_COMM_TYPE_DATA accepts sender as SAP userid.

Please let me know if you need more information.

Thank you,

Surya

Former Member
0 Kudos

Can you elaborate more about adding body of email.

Say I have output type ZINV with medium 5. In the IMG, I put the ZXXX program, Form routine and Sapscript Form name under the output ZINV of processing routines. This will execute my Z program to create the invoice and email as PDF attachment. Now I want to change the subject and add email body text in the email. In the output type under Mail title and text, I can put the mail title description here.

But If I want to include the invoice number in the title and the body of the email, according to notes 191470, I can put the routine 'TEXT_SYMBOL_REPLACE' and corresponding program 'SAPMV45A' for order entry but I am not sure what program will run for the invoice. Can you explain to me how to add email body text through SAP standard processing.

Thanks for your quick response.

Aki

Former Member
0 Kudos

Hi Akinosora,

Sorry for the late reply. Body of the email can be specified in the text element between Language and Document title. You can specify symbols like &LFA1-LIFNR& along with other text. For "Replacement of text symbols" specify program and form routine under General data tab of the output type. Here are they for Sales (Applicaton V1) SAPMV45A & TEXT_SYMBOL_REPLACE

For "Replacement of execution parameters" specify program and form routine under Mail tab of the output type. SAPMV45A & MAILAKTIONSPARAMETER

Thank you,

Surya

Former Member
0 Kudos

Hi Surya,

Thank you. I got the title correct but still could not get the email body. I put the text in the text element between language and doc title as you advised. However I got the email with the attach PDF of the order with the title have correct order number but the body of the email is still empty. If you can send me your email address, I can send you screen shot of the configuration to see what was wrong. My email is van.akinosora@gmail.com

Thanks

Former Member
0 Kudos

Hi Akinosora,

Let me check this. Also your requirement is to send email to multiple recipients. This option might not work. I have code related to it. Let me know if need it.

Thank you,

Surya.

Former Member
0 Kudos

Thanks.

Yes, my requiremtn is to email multiple recipients but I also have another requirement send to one recipient and it is nice to know if we can use the SAP standard procesing. By the way, if you use Sapscript, in the open_form function module, there is an import parameter mail_appl_obj which define exactly like mail_recipient so I wonder if we can use this para to pass another recipient list. to email. I do not know what the parameter mail_appl_obj does. I search but found nothing yet.

Former Member
0 Kudos

Hi Surya,

Check this. Look like you cannot email to multiple recipients in Sapscript or SmartForm. The only solution is you have to loop the program several time to pass each individual recipient during the open_form and close_form.

http://help.sap.com/saphelp_nw04/helpdata/en/01/37ef3aabdfb20de10000000a11402f/frameset.htm

Indirect Connection using SAPscript

Use

If your application already sends documents using SAPscript, you can connect to the Business Communication Interface (BCI) indirectly.

Activities

In order to access the BCI using SAPscript, the device type MAIL (that is, import parameter DEVICE = MAIL) must be set when you open form printing using the function module OPEN_FORM. The formatted document is then automatically transferred to the BCI and sent from there. The recipient is determined by the import parameter MAIL_RECIPIENT. This is (analogous to direct access to the BCI) a Recipient object.

Constraints

Only individual recipients can be specified as Recipient objects for the connection using SAPscript.

Therefore, distribution lists, organizational units and so on, cannot be specified. The reason for this is that the formatting of documents by SAPscript is generally recipient-dependent.

Therefore, before calling SAPscript, break down the Recipient object using the Expand method, and call SAPscript for each recipient individually.

Former Member
0 Kudos

Hi Akinosora,

I had thought of this looping method. How about performance ? Suppose I have a complex logic built into my Smartform. Wouldn't it run those many times as the number of recipients ? This is what concerned my in implementing this method. I welcome your comments on this.

Thank you,

Surya.

Former Member
0 Kudos

Honestly, to me the cleanest is creating otfdata and send email via function so_object_send like I mention in previous notes and I can control email title, subject, email body text in the email.

SmartForm use OTF format to send forms. I assume you know how to create OTF data. I do not use SmartForm but here is the code of examples I found in the book SAP SmartForm by Hertleif that using the loop method. Performance wise, since you are passing tables with data in your generated in your program before calling SmartForm generated function module so I do not think it is OK.

Let me know if it works for you.

include <cntn01>.

DATA: recipient_id LIKE swotobjid,

recipient TYPE swc_object,

address(20) TYPE c,

address_string TYPE so_name,

recipient_tab TYPE TABLE OF swc_object,

l_comm_type type soes-SNDART,

ls_recipient type PPFSRECPT.

DATA: sec_container container.

DATAL control_parameters type ssfctrlop.

control_parameters-device = 'MAIL'.

swc_clear_container container.

REFRESH recipient_tab.

swc_call_method recipient 'Expand' container.

IF sy-subrc <> 0.

  • message id sy-msgid type 'E' number sy-msgno.

ENDIF.

  • Read flat recipient objects from container

swc_get_table container 'ResultTable' recipient_tab.

IF sy-subrc NE 0.

REFRESH recipient_tab.

ENDIF.

  • Loop over flat recipient object

Loop at recipient_tab.

swc_object_to_persistent recipient_tab recipient_id.

  • now call the generated function module

call function fm_name

exporting

  • archive_index =

  • archive_parameters =

  • control_parameters =

  • mail_appl_obj =

  • mail_recipient =

  • mail_sender =

  • output_options =

  • user_settings = 'X'

customer = customer

bookings = bookings

connections = connections

  • importing document_output_info =

  • job_output_info =

  • job_output_options =

exceptions formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

others = 5.

if sy-subrc <> 0.

  • error handling

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

Endloop.

Former Member
0 Kudos

Sorry, I mean I think IT IS OK in the loop method.

In the call of SmartForm generated module you have to pass the recipient data, sender data and mail_appl_obj parameters.

If you need more details let me know.

  • now call the generated function module

call function fm_name

exporting

  • archive_index =

  • archive_parameters =

  • control_parameters =

mail_appl_obj = appl_object_id

mail_recipient = recipient_id

mail_sender = sender_id

  • output_options =

  • user_settings = 'X'

customer = customer

bookings = bookings

connections = connections

  • importing document_output_info =

  • job_output_info =

  • job_output_options =

exceptions formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

others = 5.