You can use the Business Add-In (BAdI) EDOC_PART_CONN_CHANGE_EMAIL_V2 to customize the e-mails you send to your customers. This BAdI allows you to tailor e-mail details such as addresses, subject lines, and body text. Additionally, you can modify existing attachments and add new ones.
This BAdI uses the method CHANGE_EMAIL_TO_CUSTOMER with the following parameters:
The new BAdI supports customization for the following processes:
The following example shows how to modify the sender, recipient, subject, and e-mail text, and how to add an attachment.
In addition, this example includes files of the eDocument file types: REQUEST, SEND_REQ, and SEND_RESP. These eDocument file types are defined in table EDOFILETYPE, where you can select the ones relevant for your country scenario. Note that each eDocument file type has its own MIME type. For example, requests and responses generally use the MIME type text/xml (with the attachment type XML), while PDFs use application/pdf (with the attachment type PDF).
In the code between lines 46 and 69, the raw file content is divided into chunks of 255 characters. Since you’re attaching a binary file, you need to populate the CONTENT_HEX field of the ls_attachment structure.
DATA: lv_sender LIKE LINE OF companyemailaddresses,
lv_recipient_to LIKE LINE OF customeremailaddresses,
ls_content_line LIKE LINE OF emailcontenttext.
* Add the sender
READ TABLE companyemailaddresses INTO lv_sender INDEX 1.
emailsender = lv_sender-smtp_addr.
* Add recipients (To)
LOOP AT customeremailaddresses INTO lv_recipient_to.
APPEND lv_recipient_to-smtp_addr TO emailrecipientsto.
ENDLOOP.
* Add the subject
CONCATENATE 'Invoice' edocument-source_key edocument-create_date
INTO emailsubject SEPARATED BY space.
* Add email content lines (255 characters max. per line)
ls_content_line = 'Dear Customer,'.
APPEND ls_content_line TO emailcontenttext.
ls_content_line = 'Please find attached our invoice.'.
APPEND ls_content_line TO emailcontenttext.
ls_content_line = 'This is an automated email.'.
APPEND ls_content_line TO emailcontenttext.
*Add additional files (request and responses) to the attachment
DATA: ls_attachment TYPE edoc_email_attachment_cloud,
lv_country_iso TYPE intca.
TRY.
DATA(lo_edocument) = cl_edocument_ext_es=>retrieve_by_edoc_guid(
EXPORTING
iv_edoc_guid = edocument-edoc_guid
iv_skip_interface_det = abap_true ).
DATA(lt_edocumentfile) = lo_edocument->get_edoc_files( ).
LOOP AT lt_edocumentfile INTO DATA(ls_edocumentfile)
WHERE file_type = 'REQUEST' OR
file_type = 'SEND_REQ' OR
file_type = 'SEND_RESP'.
ls_attachment-attachm_subject = ls_edocumentfile-file_name.
ls_attachment-attachm_type = 'XML'.
DATA lp_offset TYPE i.
DATA ls_solix_line TYPE edoc_attch_content_hex.
DATA lp_pdf_string_len TYPE i.
DATA lp_solix_rows TYPE i.
DATA lp_last_row_length TYPE i.
DATA lp_row_length TYPE i.
* Transform xstring to SOLIX
lp_row_length = 255.
lp_offset = 0.
lp_pdf_string_len = xstrlen( ls_edocumentfile-file_raw ).
lp_solix_rows = lp_pdf_string_len DIV lp_row_length.
lp_last_row_length = lp_pdf_string_len MOD lp_row_length.
DO lp_solix_rows TIMES.
ls_solix_line-line = ls_edocumentfile-file_raw+lp_offset(lp_row_length).
APPEND ls_solix_line TO ls_attachment-content_hex.
ADD lp_row_length TO lp_offset.
ENDDO.
IF lp_last_row_length > 0.
CLEAR ls_solix_line-line.
ls_solix_line-line = ls_edocumentfile-file_raw+lp_offset(lp_last_row_length).
APPEND ls_solix_line TO ls_attachment-content_hex.
ENDIF.
ls_attachment-attachm_size = xstrlen( ls_edocumentfile-file_raw ).
APPEND ls_attachment TO attachments.
ENDLOOP.
CATCH cx_edocument_ext INTO DATA(lx_exception).
* Throw error message
ENDTRY.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |