Advertising:
Create and send e-mail with released class for cloud development
From SAP Knowledge Base
In all possible developments the released class "CL_BCS_MAIL_MESSAGE" should be used.
In case the class is not available use the classic variant, see here.
TRY.
DATA(mail) = cl_bcs_mail_message=>create_instance( ).
mail->set_sender( 'my@unirab.org' ).
mail->add_recipient( 'r1@unirab.org' ).
mail->add_recipient( iv_address = 'r2@unirab.org' iv_copy = cl_bcs_mail_message=>cc ).
mail->set_subject( 'Cloud Dev/RAP Mail' ).
mail->set_main( cl_bcs_mail_textpart=>create_text_html( '<h1>Hi</h1><p>E-Mail created with released class for cloud dev</p>' ) ).
mail->add_attachment( cl_bcs_mail_textpart=>create_text_plain(
iv_content = 'Attachment as .txt'
iv_filename = 'Text_Attachment.txt'
) ).
mail->add_attachment( cl_bcs_mail_textpart=>create_instance(
iv_content = 'Attachment as .xml'
iv_content_type = 'text/xml'
iv_filename = 'Text_Attachment.xml'
) ).
mail = mail->send( ).
CATCH cx_bcs_mail INTI DATA(mail_cx).
"handle exceptions here
ENDTRY.
- Attachments like .pdf use class "CL_BCS_MAIL_BINARYPART"
- In case the email Client can not or is not allowed for HTML E-Mail Set alternativ main with class "ADD_MAIN_ALTERNATIVE"
- Sending emails asynchronously use method "send_async( )"
- Needs COMMIT WORK