Sunday, March 11, 2012

HOW TO SEND AUTOMAIL


report ZSENDAUTOMAIL.

*Sample Program
*
*
*REPORT zcustom_errmsg.
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 = 's777@gmail.com'.
append lt_mailrecipients .
clear lt_mailrecipients .

* Subject.
lt_mailsubject-obj_name = 'TEST'.
lt_mailsubject-obj_langu = sy-langu.
lt_mailsubject-obj_descr = 'Mail Subject'.

* Mail Contents
lt_mailtxt = 'This is a test mail'.
append lt_mailtxt. clear lt_mailtxt.

* Send Mail
call function 'SO_NEW_DOCUMENT_SEND_API1'
  exporting
    document_data              = lt_mailsubject
  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.

1 comment: