Use the sap offcie component to send emails

Source: Internet
Author: User

As a self-contained system, sap has rich resources in its development environment, including the sap office component for sending emails. The SAP component allows you to send emails to the Internet. Call function 'so _ object_send 'to send emails.CodeExample to illustrate the role of parameters.
It must be noted that the following code only provides a text attachment in the sent mail. When you use the sap office to send an email, you can include the uploaded file as an attachment to the email, or use the ALV content as an attachment (in the standard Alv, tools can send emails ). These theories are all feasible, but the younger brother does not know them yet, so here is just a brick. If you have any Jade, please refer ~~~~~

Data: object_hd_change like sood1 occurs 10 with header line, "header information of the mail body
Receivers like soos1 occurs 10 with header line,
Packing_list like soxpl occurs 10 with header line, "Mail Attachment header information
Objcont like soli occurs 10 with header line, "mail body
Att_cont like soli occurs 10 with header linobject_hd_changee, "email attachment
Att_head like soli occurs 10 with header line. "header line
Data: Count type I, length type I.
Data: lc_item1 (24) type C.
Data: lc_item2 (24) type C.
Data: lc_line_sub (29) type C.
Data: lc_line_sub2 (52) type C.
Data: ls_data type string.
Data: li_len type I.
Data: ls_title type string.

Refresh: objcont, receivers, packing_list,
Objcont, att_cont, att_head.

Clear: ATT_CONT-LINE.
Att_cont-line = 'attachment text title '.
Ls_title = att_cont-line.
Append att_cont.

* Add the table to the attachment.
Clear: ATT_CONT-LINE.
ATT_CONT-LINE = 'attachment text content.
Append att_cont. "If there is a row of content, you can append multiple times.

Move 'email content title' to objcont-line.
Append objcont.

Move 'file' to att_head-line.
Append att_head.

Describe table objcont lines count.
Describe field objcont-line length in byte mode.
Object_hd_change-objla = 'E'. "language used to create a document
Object_hd_change-objnam = 'LIST'. "document, folder or allocation list name
Object_hd_change-objdes = gs_string. "Brief description of the content char50
Object_hd_change-objsns = 'O'. "Object: sensitivity P confidential F function o Standard
Object_hd_change-objlen = count* Length. "document content size
Append object_hd_change.

* Recipient
Receivers-recextnam = 'seewood @ gmail.com '.
Receivers-recesc = 'u'. "Address type, u: Internet address
Append receivers. "recipient address

Describe table att_cont lines count. "Total number of email attachments
Describe field att_cont-line length "length of each mail line
In byte mode.
Packing_list-head_start = '1'. "object header starting line in transfer package
Packing_list-body_start = '1'. "Object content in the object package start line
Packing_list-head_num = '0'. "row number of the object header in the object package
Packing_list-body_num = count* Length. "row number of the object content in the object package
Packing_list-objtp = 'Raw'. "document category code

Packing_list-OBJDES = gs_string.
Packing_list-OBJNAM = gs_string.
* Objdes objnam
Append packing_list.

* Call the function to send an email.
Call function 'so _ object_send'
Exporting
* New object: General header data
Object_hd_change = object_hd_change
Object_type = 'Raw' "raw sap editing Program File
Sender = sy-uname "sender Username
Tables
Objcont = objcont "content
* Recipient table with send attributes
Receivers = receivers "recipient address
Packing_list = packing_list "Mail content
Att_cont = att_cont "attachment
Att_head = att_head "title
Exceptions
Active_user_not_exist = 1
Communication_failure = 2
Component_not_available = 3
Folder_not_exist = 4
Folder_no_authorization = 5
Forwarder_not_exist = 6
Note_not_exist = 7
Object_not_exist = 8
Object_not_sent = 9
Object_no_authorization = 10
Object_type_not_exist = 11
Operation_no_authorization = 12
Owner_not_exist = 13
Parameter_error = 14
Substitute_not_active = 15
Substitute_not_defined = 16
System_failure = 17
Too_much_receivers = 18
User_not_exist = 19
Originator_not_exist = 20
X_error = 21
Others = 22.
Pr_subrc = SY-SUBRC.
If SY-SUBRC = 0.
Commit work.
Endif.

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.