Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

sending an email to users from abap program

Former Member
0 Kudos
1,401

Hi experts ,

How to send an email to users from abap program ...

i need full coding please..so that i can copy and paste it in my program.

Thank you in advance.

Rajasekhar.P

7 REPLIES 7

Former Member
0 Kudos
371

Hi Peravalli,

You can use class CL_BCS (if available) or FM SO_DOCUMENT_SEND_API1' for sending emails.

Regards,

John.

Former Member
0 Kudos
371

refer this...

data: maildata type sodocchgi1.

data: mailtxt type table of solisti1 with header line.

data: mailrec type table of somlrec90 with header line.

start-of-selection.

clear: maildata, mailtxt, mailrec.

refresh: mailtxt, mailrec.

maildata-obj_name = 'TEST'.

maildata-obj_descr = 'Test'.

maildata-obj_langu = sy-langu.

mailtxt-line = 'This is a test'.

append mailtxt.

mailrec-receiver = sy-uname.

mailrec-rec_type = 'B'.

append mailrec.

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = maildata

document_type = 'RAW'

put_in_outbox = 'X'

tables

object_header = mailtxt

object_content = mailtxt

receivers = mailrec

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 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

former_member182354
Contributor
0 Kudos
371

Hi Venkat,

Thing is that there is a function module for the same.

Function module name is 'MESSAGE_SEND_AS_MAIL'. I am suggesting this function module bcoz I understood that you want to send a message that you get in your program as mail to the receipient.

Using this FM is simple: Just pass the MESG - ID and MESG NO to this Function module. Then create an Internal table of structure 'SOMLRECI1' and populate that Internal table with the receipient info and pass it to the FM.

All the best ..This is an exciting requirement..

Regards,

Raghav

Former Member
0 Kudos
371

Hi,

You can use the function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send mail from SAP.

To learn the functionality you can use the standard program RSWNSENDMAIL1.

Regards,

Renjith Michael.

former_member156446
Active Contributor
0 Kudos
371

Hi Venkat

check the below simple code to convert spool to HTML and email it

data: list type table of abaplist with header line.

data: htmllines type table of w3html with header line.

data: maildata like sodocchgi1.

data: mailtxt like solisti1 occurs 10 with header line.

data: mailrec like somlrec90 occurs 0 with header line.

start-of-selection.

  • Produce a list

do 100 times.

write:/ sy-index, at 30 sy-index, at 50 sy-index.

enddo.

  • Save the list

call function 'SAVE_LIST'

tables

listobject = list

exceptions

list_index_invalid = 1

others = 2.

  • Convert the list

call function 'WWW_LIST_TO_HTML'

tables

html = htmllines.

  • Send mail

maildata-obj_name = 'TEST'.

maildata-obj_descr = 'Test Subject'.

loop at htmllines.

mailtxt = htmllines.

append mailtxt.

endloop.

mailrec-receiver = 'you@yourcompany.com'.

mailrec-rec_type = 'U'.

append mailrec.

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = maildata

document_type = 'HTM'

put_in_outbox = 'X'

tables

object_header = mailtxt

object_content = mailtxt

receivers = mailrec

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 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

0 Kudos
371

Look at BCS_EXAMPLE* abaps

Former Member
0 Kudos
371

Hi,

Please refer to the link below :

http://www.sapdev.co.uk/reporting/email/email_sapmail.htm

Thanks,

Sriram Ponna.