Nesnesiz HTML içerikli E-Posta gönderimi
Class ile hazırlanmış basit bir e-posta gönderme formu aşağıdadır :
FORM f_send_mail .
DATA: l_send_request TYPE REF TO cl_bcs, " Send request
l_body TYPE bcsy_text, " Mail body
wa_text TYPE soli, " Work area for attach
l_document TYPE REF TO cl_document_bcs, " Mail body
l_sender TYPE REF TO if_sender_bcs, " Sender address
l_recipient TYPE REF TO if_recipient_bcs, " Recipient
l_size TYPE sood-objlen, " Size of Attachment
l_lines TYPE i, " Lines count
l_email TYPE ad_smtpadr, " Email ID
l_extension TYPE soodk-objtp VALUE `BIN`. " TXT format
data: lt_prog_mail type STANDARD TABLE OF ztr_prog_email.
DATA : ls_prog_mail TYPE ztr_prog_email.
DATA : lv_date TYPE char10.
DATA : lv_time TYPE char8.
DATA : lv_zaman TYPE char200.
DATA : lv_baslik TYPE SO_OBJ_DES.
write sy-datum to lv_date DD/MM/YYYY.
write sy-uzeit to lv_time DD/MM/YYYY.
CONCATENATE `Tarih/Saat:` lv_date lv_time into lv_zaman separated by space.
select * into TABLE lt_prog_mail from ztr_prog_email where PROGNAME = sy-repid.
CHECK lt_prog_mail[] is NOT INITIAL.
* Prepare mail body
APPEND `<html><body>` TO l_body.
APPEND `<P>` TO l_body.
APPEND `İyi günler` TO l_body.
APPEND `<BR>SAP tabloları güncellenmiştir.` TO l_body.
APPEND `<BR>` TO l_body.
APPEND lv_zaman TO l_body.
APPEND space TO l_body.
APPEND space TO l_body.
APPEND `<BR>Not: Bu mail SAP sistemi tarafından otomatik gönderilmiştir.` TO l_body.
APPEND space TO l_body.
APPEND `<BR>Saygılarımla. ` TO l_body. APPEND space TO l_body.
APPEND `</P>` TO l_body.
APPEND `</body></html>` TO l_body.
CONCATENATE `JOB son çalışma : ` lv_date into lv_baslik SEPARATED BY space.
* Creates persistent send request
l_send_request = cl_bcs=>create_persistent( ).
* Craete document for mail body
l_document = cl_document_bcs=>create_document(
i_type = `HTM`
i_text = l_body " Mail body
i_subject = lv_baslik ).
CALL METHOD L_SEND_REQUEST->SET_DOCUMENT( L_DOCUMENT ).
* Sender addess
CLEAR l_email.
l_email = `NoReply@sapurlus.com`.
l_sender = cl_cam_address_bcs=>create_internet_address( l_email ).
CALL METHOD l_send_request->set_sender
EXPORTING
i_sender = l_sender.
LOOP AT lt_prog_mail INTO ls_prog_mail .
l_email = ls_prog_mail-email.
l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
* Add recipient address to send request
CALL METHOD l_send_request->add_recipient
EXPORTING
i_recipient = l_recipient
i_express = ` `
i_copy = ` `
i_blind_copy = ` `
i_no_forward = ` `.
ENDLOOP.
* Request only error receipts
l_send_request->set_status_attributes( `E` ).
* Send mail
CALL METHOD l_send_request->send( ).
COMMIT WORK.
ENDFORM.