« Return to the blog entry
These kind of utility classes are always useful.
Maybe you are in need of an ABAP version some day?
(This is just one method of the class but maybe you can imagine what it does...)
method send_mail.
data:
lr_sender type ref to cl_cam_address_bcs,
lv_address type ad_smtpadr,
lv_type type so_obj_tp,
lv_sender type uname,
lr_ex_send_req type ref to cx_send_req_bcs,
lr_ex_address type ref to cx_address_bcs,
lr_ex_doc type ref to cx_document_bcs,
lv_result type os_boolean.
lv_type = im_type.
lv_sender = im_sender.
if lv_type is initial.
lv_type = 'HTM'. "HTML-Mail
endif.
if lv_sender is initial.
lv_sender = sy-uname.
try .
* Maildokument erzeugen
document = cl_document_bcs=>create_document(
i_type = im_type
i_text = body
i_subject = subject ).
* Dokument an Senderequest hängen
call method send_request->set_document( document ).
* Sender Objekt erzeugen und Sender hinzufügen
sender_object = cl_sapuser_bcs=>create( lv_sender ).
call method send_request->set_sender
exporting
i_sender = sender_object.
lv_address = im_recipient.
* Empfänger hinzufügen
recipient = cl_cam_address_bcs=>create_internet_address( lv_address ).
call method send_request->add_recipient
i_recipient = recipient
i_express = ' '
i_copy = ' '
i_blind_copy = ' '.
send_request->set_send_immediately( 'X' ).
* Einstellungen für die Statusrückmeldung
send_request->set_status_attributes( 'E' ).
* Dokument senden
lv_result = send_request->send( ).
catch cx_send_req_bcs into lr_ex_send_req.
clear log_msg.
log_msg-msgv1 = lr_ex_send_req->get_text( ).
log->bal_msg_add( is_msg = log_msg ).
catch cx_address_bcs into lr_ex_address.
log_msg-msgv1 = lr_ex_address->get_text( ).
catch cx_document_bcs into lr_ex_doc.
log_msg-msgv1 = lr_ex_doc->get_text( ).
endtry.
message i000 with lv_result into log_msg-msgv1.
commit work.
endmethod.
These kind of utility classes are always useful.
Maybe you are in need of an ABAP version some day?
(This is just one method of the class but maybe you can imagine what it does...)
method send_mail.
data:
lr_sender type ref to cl_cam_address_bcs,
lv_address type ad_smtpadr,
lv_type type so_obj_tp,
lv_sender type uname,
lr_ex_send_req type ref to cx_send_req_bcs,
lr_ex_address type ref to cx_address_bcs,
lr_ex_doc type ref to cx_document_bcs,
lv_result type os_boolean.
lv_type = im_type.
lv_sender = im_sender.
if lv_type is initial.
lv_type = 'HTM'. "HTML-Mail
endif.
if lv_sender is initial.
lv_sender = sy-uname.
endif.
try .
* Maildokument erzeugen
document = cl_document_bcs=>create_document(
i_type = im_type
i_text = body
i_subject = subject ).
* Dokument an Senderequest hängen
call method send_request->set_document( document ).
* Sender Objekt erzeugen und Sender hinzufügen
sender_object = cl_sapuser_bcs=>create( lv_sender ).
call method send_request->set_sender
exporting
i_sender = sender_object.
lv_address = im_recipient.
* Empfänger hinzufügen
recipient = cl_cam_address_bcs=>create_internet_address( lv_address ).
call method send_request->add_recipient
exporting
i_recipient = recipient
i_express = ' '
i_copy = ' '
i_blind_copy = ' '.
send_request->set_send_immediately( 'X' ).
* Einstellungen für die Statusrückmeldung
send_request->set_status_attributes( 'E' ).
* Dokument senden
lv_result = send_request->send( ).
catch cx_send_req_bcs into lr_ex_send_req.
clear log_msg.
log_msg-msgv1 = lr_ex_send_req->get_text( ).
log->bal_msg_add( is_msg = log_msg ).
catch cx_address_bcs into lr_ex_address.
clear log_msg.
log_msg-msgv1 = lr_ex_address->get_text( ).
log->bal_msg_add( is_msg = log_msg ).
catch cx_document_bcs into lr_ex_doc.
clear log_msg.
log_msg-msgv1 = lr_ex_doc->get_text( ).
log->bal_msg_add( is_msg = log_msg ).
endtry.
clear log_msg.
message i000 with lv_result into log_msg-msgv1.
log->bal_msg_add( is_msg = log_msg ).
commit work.
endmethod.