Un form que utilicé para enviar correo en formato HTML y que además adjuntaba el mismo mensaje como archivo en Excel.
DATA str_htm TYPE string.
DATA send_request TYPE REF TO cl_bcs.
DATA xhtml_string TYPE xstring.
DATA str_subject(50) VALUE 'Notificacion Laboratorio'.
data t_hex TYPE solix_tab.
data document TYPE REF TO cl_document_bcs.
data sender TYPE REF TO cl_sapuser_bcs.
data recipient TYPE REF TO if_recipient_bcs.
data bcs_exception TYPE REF TO cx_bcs.
data mailtext type soli_tab.
DATA status_mail TYPE bcs_stml.
data lx_document_bcs TYPE REF TO cx_document_bcs.
str_htm = '<html><body>texto html</body></html>'.
* ver tema ABAP Tips: Texto dinámico en correo para complementar
TRY.
send_request = cl_bcs=>create_persistent( ).
** cuerpo del mensaje
* mailtext = cl_document_bcs=>string_to_soli( str_htm ).
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = str_htm
IMPORTING
buffer = xhtml_string
EXCEPTIONS
failed = 1
OTHERS = 2.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = xhtml_string
TABLES
binary_tab = t_hex.
* generar cuerpo del mensaje
document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = mailtext
i_hex = t_hex
i_subject = str_subject ).
* adjuntar mismo correo
document->add_attachment(
EXPORTING
i_attachment_type = 'XLS'
i_attachment_subject = 'ContenidoHTM'
i_att_content_hex = t_hex ).
* Add document to send request
CALL METHOD send_request->set_document( document ).
* Get sender object
sender = cl_sapuser_bcs=>create( sy-uname ).
* Add sender
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* Add recipient with its respective attributes to send request
recipient = cl_cam_address_bcs=>create_internet_address( 'correo' ).
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient.
* Set that you don't need a Return Status E-mail
status_mail = 'N'.
CALL METHOD send_request->set_status_attributes
EXPORTING
i_requested_status = status_mail
i_status_mail = status_mail.
* set send immediately flag
send_request->set_send_immediately( 'X' ).
* Send document
CALL METHOD send_request->send( ).
COMMIT WORK.
CATCH cx_document_bcs INTO lx_document_bcs.
CATCH cx_bcs INTO bcs_exception.
ENDTRY.
ENDFORM. " ENVIA_CORREO
No hay comentarios:
Publicar un comentario