Skip to Content

Many times it is required to send simple formated  mail (Some lines in bold/Italic in the body of mail )from ABAP, like mail notification after PR/PO is released.

in such case we can use the FM

SO_NEW_DOCUMENT_SEND_API1 with document_type as HTML which will enable us to print few lines in desired formate (e.g some text in bold).

In such cases the below Sample code can be used to trigger the formatted mail as per the requirement.

* Data Declarations

DATA: lt_mailsubject    TYPE sodocchgi1.

DATA: lt_mailrecipients TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE.

DATA: lt_mailtxt        TYPE STANDARD TABLE OF soli WITH HEADER LINE.

* Recipients

lt_mailrecipients-rec_type = ‘U’.

lt_mailrecipients-receiver = ‘gejo.john@lntinfotech.com.

APPEND lt_mailrecipients .

CLEAR lt_mailrecipients .

* Subject.

lt_mailsubject-obj_name = ‘Test’.

lt_mailsubject-obj_langu = sy-langu.

lt_mailsubject-obj_descr = ‘SAP-ABAP Mail trigger& few lines bold in body’.

* Mail Contents

CONCATENATE ‘<br>’ ‘This is a SAP Mail sending code and can be used in simple notification purpose etc’ ‘</br>’ into lt_mailtxt.

APPEND lt_mailtxt. CLEAR lt_mailtxt.

CONCATENATE ‘<br>’ ‘ ‘ ‘</br>’ into lt_mailtxt.

APPEND lt_mailtxt. CLEAR lt_mailtxt.

concatenate ‘<br>’ ‘<b>’ ‘This part shows how to make specific text as bold’ ‘</b>:’ ‘</br>’ into lt_mailtxt.

APPEND lt_mailtxt. CLEAR lt_mailtxt.

concatenate ‘<br>’ ‘<I>’ ‘This part shows how to make specific text as ITALIC’ ‘</I>:’ ‘</br>’ into lt_mailtxt.

APPEND lt_mailtxt. CLEAR lt_mailtxt.

CONCATENATE ‘<br>’ ‘ ‘ ‘</br>’ into lt_mailtxt.

APPEND lt_mailtxt. CLEAR lt_mailtxt.

CONCATENATE ‘<br>’ ‘Thanks’ ‘</br>’ into lt_mailtxt.

APPEND lt_mailtxt. CLEAR lt_mailtxt.

CONCATENATE ‘<br>’ ‘Regards’ ‘</br>’ into lt_mailtxt.

APPEND lt_mailtxt. CLEAR lt_mailtxt.

* Send Mail

CALL FUNCTION ‘SO_NEW_DOCUMENT_SEND_API1’

  EXPORTING

    document_data              = lt_mailsubject

    document_type                    = ‘HTM’

  TABLES

    object_content             = lt_mailtxt

    receivers                  = lt_mailrecipients

  EXCEPTIONS

    too_many_receivers         = 1

    document_not_sent          = 2

    document_type_not_exist    = 3

    operation_no_authorization = 4

    parameter_error            = 5

    x_error                    = 6

    enqueue_error              = 7

    OTHERS                     = 8.

IF sy-subrc EQ 0.

  COMMIT WORK.

* Push mail out from SAP outbox

  SUBMIT rsconn01 WITH mode = ‘INT’ AND RETURN.

ENDIF.

Hope this will be usefull to you,

Thanks,

Gejo john

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply