A quite easy way to send email in ABAP
2011-08-23 11:23
323 查看
report zrich_0002.
data: maildata likesodocchgi1.
data: mailtxt like solisti1 occurs 10 with header line.
data: mailrec like somlrec90 occurs 0 with header line.
start-of-selection.
clear: maildata, mailtxt, mailrec.
refresh: mailtxt,mailrec.
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test Subject'.
mailtxt = '<html>'.
append mailtxt.
mailtxt = '<body>'.
append mailtxt.
mailtxt = '<b>This isSAP</b>'.
append mailtxt.
mailtxt = '<a href="#"target="_blank">SAPHyperlink</a> '.
append mailtxt.
mailtxt = '</body>'.
append mailtxt.
mailtxt = '</html>'.
append mailtxt.
mailrec-receiver = 'you@yourcompany.com'.
mailrec-rec_type ='U'.
append mailrec.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
document_type =
'HTM'
put_in_outbox =
'X'
tables
object_header = mailtxt
object_content = mailtxt
receivers = mailrec
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.
---------------------------------------------------------------------------------------------
REPORT zsendmail.
DATA:lv_title TYPE so_obj_des,
send_request TYPE REF TOCL_BCS,
document TYPE REF TO
CL_DOCUMENT_BCS,
conlengths TYPE so_obj_len,
html TYPE STANDARD TABLE OF
w3html,
wa_html TYPEw3html,
sender_id TYPE REF TO
IF_SENDER_BCS,
recipient TYPE REF TO
IF_RECIPIENT_BCS,
sent_to_all TYPE os_boolean,
bcs_exception TYPE REF TO cx_bcs,
bcs_message TYPE string.
lv_title = 'This is the title'.
wa_html-line ='<html><body>'.
APPEND wa_html TO html.
...
wa_html-line ='</body></html>'.
APPEND wa_html TO html.
TRY.
CLEARsend_request.
send_request =cl_bcs=>create_persistent().
CLEARdocument .
document= cl_document_bcs=>create_document(
i_type = 'HTM'
i_text= html
i_length = conlengths
i_subject = lv_title ).
* Add document to sendrequest
CALL METHODsend_request->set_document(document ).
* Construct sender andreceiver
CLEAR:sender_id , recipient .
sender_id =cl_cam_address_bcs=>create_internet_address('abc@zh.cn' ).
recipient =cl_cam_address_bcs=>create_internet_address('bcd@zh.cn' ).
* Set sender
CALL METHODsend_request->set_sender
EXPORTING
i_sender = sender_id.
* Add recipient with itsrespective attributes to send request
CALL METHODsend_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* Set E-mail sendingoptions
CALL METHODsend_request->set_status_attributes
EXPORTING
i_requested_status = 'E'
i_status_mail = 'E'.
CALL METHODsend_request->set_send_immediately( 'X' ).
* Send document
CALL METHODsend_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
IFsent_to_all = 'X'.
MESSAGE 'Mail sent successfully ' TYPE 'S'.
ENDIF.
COMMITWORK.
CATCH cx_bcs INTO bcs_exception.
bcs_message= bcs_exception->get_text( ).
MESSAGEbcs_exception TYPE 'E'.
EXIT.
ENDTRY.
******************************************
*get sender email address.
CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
EXPORTING
USER_NAME = LV_BNAME
* READ_DB_DIRECTLY = ' '
IMPORTING
USER_ADDRESS = FS_ADDR
USER_USR03 = FS_USR03
EXCEPTIONS
USER_ADDRESS_NOT_FOUND = 1
OTHERS = 2.
data: maildata likesodocchgi1.
data: mailtxt like solisti1 occurs 10 with header line.
data: mailrec like somlrec90 occurs 0 with header line.
start-of-selection.
clear: maildata, mailtxt, mailrec.
refresh: mailtxt,mailrec.
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test Subject'.
mailtxt = '<html>'.
append mailtxt.
mailtxt = '<body>'.
append mailtxt.
mailtxt = '<b>This isSAP</b>'.
append mailtxt.
mailtxt = '<a href="#"target="_blank">SAPHyperlink</a> '.
append mailtxt.
mailtxt = '</body>'.
append mailtxt.
mailtxt = '</html>'.
append mailtxt.
mailrec-receiver = 'you@yourcompany.com'.
mailrec-rec_type ='U'.
append mailrec.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
document_type =
'HTM'
put_in_outbox =
'X'
tables
object_header = mailtxt
object_content = mailtxt
receivers = mailrec
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.
---------------------------------------------------------------------------------------------
REPORT zsendmail.
DATA:lv_title TYPE so_obj_des,
send_request TYPE REF TOCL_BCS,
document TYPE REF TO
CL_DOCUMENT_BCS,
conlengths TYPE so_obj_len,
html TYPE STANDARD TABLE OF
w3html,
wa_html TYPEw3html,
sender_id TYPE REF TO
IF_SENDER_BCS,
recipient TYPE REF TO
IF_RECIPIENT_BCS,
sent_to_all TYPE os_boolean,
bcs_exception TYPE REF TO cx_bcs,
bcs_message TYPE string.
lv_title = 'This is the title'.
wa_html-line ='<html><body>'.
APPEND wa_html TO html.
...
wa_html-line ='</body></html>'.
APPEND wa_html TO html.
TRY.
CLEARsend_request.
send_request =cl_bcs=>create_persistent().
CLEARdocument .
document= cl_document_bcs=>create_document(
i_type = 'HTM'
i_text= html
i_length = conlengths
i_subject = lv_title ).
* Add document to sendrequest
CALL METHODsend_request->set_document(document ).
* Construct sender andreceiver
CLEAR:sender_id , recipient .
sender_id =cl_cam_address_bcs=>create_internet_address('abc@zh.cn' ).
recipient =cl_cam_address_bcs=>create_internet_address('bcd@zh.cn' ).
* Set sender
CALL METHODsend_request->set_sender
EXPORTING
i_sender = sender_id.
* Add recipient with itsrespective attributes to send request
CALL METHODsend_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* Set E-mail sendingoptions
CALL METHODsend_request->set_status_attributes
EXPORTING
i_requested_status = 'E'
i_status_mail = 'E'.
CALL METHODsend_request->set_send_immediately( 'X' ).
* Send document
CALL METHODsend_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
IFsent_to_all = 'X'.
MESSAGE 'Mail sent successfully ' TYPE 'S'.
ENDIF.
COMMITWORK.
CATCH cx_bcs INTO bcs_exception.
bcs_message= bcs_exception->get_text( ).
MESSAGEbcs_exception TYPE 'E'.
EXIT.
ENDTRY.
******************************************
*get sender email address.
CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
EXPORTING
USER_NAME = LV_BNAME
* READ_DB_DIRECTLY = ' '
IMPORTING
USER_ADDRESS = FS_ADDR
USER_USR03 = FS_USR03
EXCEPTIONS
USER_ADDRESS_NOT_FOUND = 1
OTHERS = 2.
相关文章推荐
- how to solve the problem which is the imail software can not send email in wan,but can send email in lan.
- Easy way to implement Asynchronized Product Filtering(Layered Navigation) in Magento
- The easy way to execute sudo command in Python using subprocess.Popen
- an easy way to debug windows service in .net
- An easy way to change colour in text control
- prjSendMailInUniversity - How to send email using VB &amp; Winsock - 邮件发送接收程序 - VB6 + Winsock
- Using exchange server to send email in Powershell
- Enable PO approval process to send PO in PDF format via email
- The Easy Way To Get Recent Comments In WordPress
- Easy way to change collation of all database objects in SQL Server
- Core - Provide an easy way to store administrator and user model differences in a custom store (e.g., in a database)
- Send an e-mail by ABAP in OO way
- Easy way to estimate a table size in the future
- Send email in ABAP
- iOS Programming 101: How To Send Email in Your iPhone App
- How to make NAnt send an email using a real account
- Fastest Way to Update Rows in a Large Table in SQL Server
- An easy way to customize a scrollbar for a control
- What is the best way to implement a heartbeat in C++ to check for socket connectivity?
- The Best Way to Unit Test in Android