In SAP, how does one send attachments by email? How do I display Chinese characters in the attachment?

Source: Internet
Author: User
Tags zip folder

 

After multiple studies and tests, all attachments can be sent normally and the actual Chinese characters can be displayed normally.

 

For the key code, see the red font section:

 

*&---------------------------------------------------------------------*
* & Form send_email_with_attachment
*&---------------------------------------------------------------------*
Form send_email_with_attachment.
Data: binary_content type solix_tab.
Data: xl_content type xstring.

Constants:
Con_tab Type C value cl_abap_char_utilities => horizontal_tab,
Con_cret Type C value cl_abap_char_utilities => cr_lf.

Data: xlcontent type xstring,
Conlength type I,
Conlengths type so_obj_len,
Result_content type string,
Wa_string type string, "This holds all of your data
Wa_str_temp type string,
Dummy type string.

Data: send_request type ref to cl_bcs.
Data: Text Type bcsy_text.
Data: Document Type ref to cl_document_bcs.
Data: sender type ref to if_sender_bcs.
Data: Recipient type ref to if_recipient_bcs.
Data: recipients type bcsy_smtpa.
Data: bcs_exception type ref to cx_bcs.
Data: sent_to_all type OS _boolean.

Data: e_r_page type ref to cl_rsr_www_page.
Data: content_length type w3param-cont_len,
Content_type type w3param-cont_type,
Return_code type w3param-ret_code.
Data: HTML type standard table of w3html.
Data: Server Type string,
Port type string.
Data: wa_rec type ad_smtpadr.
Data: bcs_message type string.

Data: Subject type so_obj_des.
Data: sender_id type ad_smtpadr.
Data: email type ad_smtpadr.

Data: gv_file type string,
Gv_zipfilehex type xstring,
Go_zipper type ref to cl_abap_zip. "The ZIP folder object

Data: lp_size type so_obj_len,
Lv_ I type I.

Refresh binary_content.
Clear wa_string.
Clear: lp_size, lv_ I.
Loop at it_html.
Clear: xl_content.
* Convert the string data to xstring
Call function 'scms _ string_to_xstring'
Exporting
TEXT = it_html-line
Mimetype = 'dat'
Encoding = '000000' "4110 ng, 4103 ng, 8400 is OK
Importing
Buffer = xl_content
Exceptions
Failed = 1
Others = 2.

Call function 'scms _ xstring_to_binary'
Exporting
Buffer = xl_content
Append_to_table = 'X'
Importing
Output_length = lv_ I
Tables
Binary_tab = binary_content.

Add lv_ I to lp_size.

Endloop.

Lp_size = lp_size * 6.

* "Title
Subject = p_subj.

Sender_id = p_sender.

Clear p_att_name.
Concatenate wa_header-reinr '.htm' into p_att_name.

* Refresh text.
Clear result_content.
* The Body message
Loop at zmess.
If result_content is initial.
Concatenate zmess-zline' <br> 'into result_content.
Else.
Concatenate result_content zmess-zline '<br> 'into result_content.
Endif.
Endloop.

Conlength = strlen (result_content ).
Conlengths = conlength.
Call function 'scms _ string_to_ftext'
Exporting
TEXT = result_content
Tables
Ftext_tab = text.

Try.
Clear send_request.

Send_request = cl_bcs => create_persistent ().

Clear document.
Document = cl_document_bcs => create_document (
I _type = 'htm'
I _text = text
I _length = conlengths
I _subject = subject ).

Call method document-> add_attachment
Exporting
I _attachment_type = 'htm'
I _attachment_subject = p_att_name "'trip.htm'" attachment name
I _att_content_hex = binary_content.

* Add document to send request
Call method send_request-> set_document (document ).

Clear sender.
Sender = cl_cam_address_bcs => create_internet_address (sender_id ).
Call method send_request-> set_sender
Exporting
I _sender = sender.

Clear wa_rec.

Clear recipient.
Wa_rec = p_receip.
Recipient = cl_cam_address_bcs => create_internet_address (
Wa_rec ).

Call method send_request-> add_recipient
Exporting
I _recipient = recipient.

Call method send_request-> set_status_attributes
Exporting
I _requested_status = 'E'
I _status_mail = 'E '.

Call method send_request-> set_send_immediately ('x ').
* ---------- Send document ---------------------------------------

Call method send_request-> send (
Exporting
I _with_error_screen = 'X'
Processing ing
Result = sent_to_all ).
If sent_to_all = 'x '.
* Append 'mail sent successfully 'to return.
Endif.
Commit work.
Catch cx_bcs into bcs_exception.
Bcs_message = bcs_exception-> get_text ().
* Append bcs_message to return.
Exit.
Endtry.
Endform. "send_email_with_attachment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.