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: 

how to!!!!!

Former Member
0 Kudos

Hi all,

Somebody know how to send a email from sap to an

external email?

And Where i can find the documentation to configure the sap server to let me seng a email?

Regards,

Jose Roberto

Message was edited by:

Jose Roberto Milan

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Use the FM SO_NEW_DOCUMENT_SEND_API1

Check this link for a sample code

http://sap.ionelburlacu.ro/sap0/abap011.htm

Thanks,

Naren

7 REPLIES 7

Former Member
0 Kudos

Hi jose,

Try this sample code :-

REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.

DATA : BEGIN OF ITAB OCCURS 0,

PERNR LIKE PA0001-PERNR,

ENAME LIKE PA0001-ENAME,

END OF ITAB.

DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,

receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,

packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,

listobject LIKE abaplist OCCURS 10,

compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,

w_object_hd_change LIKE sood1,

compressed_size LIKE sy-index.

START-OF-SELECTION.

SELECT PERNR ENAME

INTO CORRESPONDING FIELDS OF TABLE ITAB

FROM PA0001

WHERE PERNR < 50.

LOOP AT ITAB.

WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50

SY-VLINE.

ENDLOOP.

  • Receivers

receiver_list-recextnam = 'EXTERNAL-MAIL-ID@YAHOO.COM'. "-->

  • EMAIL ADDRESS

RECEIVER_list-RECESC = 'E'. "<-

RECEIVER_list-SNDART = 'INT'."<-

RECEIVER_list-SNDPRI = '1'."<-

APPEND receiver_list.

  • General data

w_object_hd_change-objla = sy-langu.

w_object_hd_change-objnam = 'Object name'.

w_object_hd_change-objsns = 'P'.

  • Mail subject

w_object_hd_change-objdes = 'Message subject'.

  • Mail body

APPEND 'Message content' TO message_content.

  • Attachment

CALL FUNCTION 'SAVE_LIST'

EXPORTING

list_index = '0'

TABLES

listobject = listobject.

CALL FUNCTION 'TABLE_COMPRESS'

IMPORTING

compressed_size = compressed_size

TABLES

in = listobject

out = compressed_attachment.

DESCRIBE TABLE compressed_attachment.

CLEAR packing_list.

packing_list-transf_bin = 'X'.

packing_list-head_start = 0.

packing_list-head_num = 0.

packing_list-body_start = 1.

packing_list-body_num = sy-tfill.

packing_list-objtp = 'ALI'.

packing_list-objnam = 'Object name'.

packing_list-objdes = 'Attachment description'.

packing_list-objlen = compressed_size.

APPEND packing_list.

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

object_hd_change = w_object_hd_change

object_type = 'RAW'

owner = sy-uname

TABLES

objcont = message_content

receivers = receiver_list

packing_list = packing_list

att_cont = compressed_attachment.

Reward if helpful,

keerthi

0 Kudos

hi,

but how it works???

0 Kudos

It works because of the SAPconnect which is in between the program and the external mail server. You need to have an mail server configure in SAPconnect in order for it to work. Have your basis guys set this up in transaction SCOT.

Regards,

Rich Heilman

0 Kudos

You can use this FM SO_OBJECT_SEND to send emails from SAP to external mail system like outlook or lotus.

Check the status of transmission in SOST t-code.

Thanks,

Santosh

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yep, this has been covered many times in this forum. You might want to search for ...... things like SO_OBJECT_SEND, or SO_NEW_DOCUMENT_SEND_API1, or

SO_NEW_DOCUMENT_ATT_SEND_API1.

Here also is a very simple program. You must also have SAPconnect configured correctly. You can force the SEND process using the commented program at the bottom of this example.

report zrich_0003 .

  • For API

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 = 'you@yourcompany.com'.

mailrec-rec_type = 'U'.

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.

  • submit rsconn01 with mode = 'INT' and return.

Regards,

Rich Heilman

Message was edited by:

Rich Heilman

Former Member
0 Kudos

Hi,

Use the FM SO_NEW_DOCUMENT_SEND_API1

Check this link for a sample code

http://sap.ionelburlacu.ro/sap0/abap011.htm

Thanks,

Naren

amit_khare
Active Contributor
0 Kudos

Hi,

Check Amit Mittal's reply on this thread.

This is what he suggested to me and this program really fulfill all the email related requirements.

Regards,

Amit