5 1 1 1 1 1 Rating 100% (10 Votes)
Everybody sends mails from SAP, some are still using old FM SO_NEW_DOCUMENT_ATT_SEND_API1 but some CL_BCS class. This class is really powerful but it has one disadvantage - it does commit work, and not only when sending emails but also during adding of attachments. In this case it's really not safe to use this class in BADIs or User-Exits, but there is one replacement for CL_BCS -> CL_BCS_MESSAGE. This class only collects the data, and when send method is run then calling a FM SBCS_SEND with destination NONE, or SBCS_SEND_UPDATE in update task, depending what attributes are passed to the class. It means you can use it also in BADIs or User-Exits where commits are not welcomed.
 
 
 
 
You can find sample programs in SAP: RSBCS_EXAMPLE_EMAIL or RSBCS_EXAMPLE_EMAIL_SIMPLE, or you can look at this small piece of code bellow to see how it is easy to use this class.
 

try.
    data(msgnew cl_bcs_message).
    msg->set_subject'My test email'  ).
    msg->add_recipient(
      exporting
        iv_address      'This email address is being protected from spambots. You need JavaScript enabled to view it.'
*        iv_commtype     = iv_commtype    " Communication Type
         iv_visible_name 'WRITE Yours'    " Display Name of an Address
*        iv_copy         = iv_copy    " Copy Recipients (None, CC, BCC)
*        iv_fax_country  = iv_fax_country    " Country for Telephone/Fax Number
    ).
   msg->set_sender(
     exporting
       iv_address      'This email address is being protected from spambots. You need JavaScript enabled to view it.'    " Communication Address (for INT, FAX, SMS, and so on)
*       iv_commtype     = iv_commtype    " Communication Type
        iv_visible_name 'Do not reply '    " Display Name of an Address
*       iv_fax_country  = iv_fax_country    " Country for Telephone/Fax Number
   ).
   msg->set_main_doc(
     exporting
       iv_contents_txt |<html><head></head><body><br/><b>TEST MESSAGE</b><br/><br/>|
                        && |sample from <a href='http://ABAPblog.com'>ABAPblog.com</a></body></html>|
*       iv_contents_bin = iv_contents_bin    " Main Document, First Body Part (Binary)
       iv_doctype      'htm'    " Document Category
*       iv_codepage     = iv_codepage    " Character Set of a Document
   ).
   msg->set_send_immediatelyabap_true ).
   msg->send).
catch cx_bcs_send into data(ex).
    message ex->get_texttype 'E'.
endtry.

 
Have fun!