Application Development and Automation 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: 
Read only

Sending EMail from ABAP Program Configuration+Code(Step by Step)

Former Member
0 Likes
1,011

Dear All,

Please anybody can provide me Step by Step document for sending Email from ABAP Program.

Thanks,

RP

9 REPLIES 9
Read only

Former Member
0 Likes
958

Hi,

You can use the fun module:SO_NEW_DOCUMENT_ATT_SEND_API1 to send mail;

see the sample code:

]----


  • INCLUDE ZINCUSMAIL *

----


include <symbol>.

data : i_doc_data like sodocchgi1.

data : begin of i_pack_list occurs 0.

include structure sopcklsti1.

data : end of i_pack_list.

data : begin of i_receivers occurs 0.

include structure somlreci1.

data : end of i_receivers.

data : begin of i_contents occurs 0.

include structure solisti1.

data : end of i_contents.

data : begin of i_header occurs 0.

include structure solisti1.

data : end of i_header.

data : begin of i_att occurs 0.

include structure solisti1.

data : end of i_att.

  • Internal Table for Internet address.

data: begin of it_inad occurs 0,

kunnr like kna1-kunnr, " Customer Code

name1 like kna1-name1, " Customer Name

ssobl like knkk-ssobl, " Security Deposit

klimk like knkk-klimk, " Credit Limit

opbal like bsid-wrbtr, " Opening Balance

clbal like bsid-wrbtr, " Closing Balance

smtp like adr6-smtp_addr, " Internet mail (SMTP) address

end of it_inad.

data : pdf_line(134),

asdf like pdf_line occurs 0 with header line.

data : pdf_table like tline occurs 0 with header line,

pdf_fsize type i.

data : stuff(65000),

len type i,

pos type i,

tab_lines like sy-tabix.

data: spoolid type tsp01-rqident,

spdel type tsp01sys.

data: v_gjahrt like bsid-gjahr,

fmondest(10),

tmondest(10),

kunnr1 like kna1-kunnr,

gjah(4),

fmon(10).

&----


*& Form hide_write

&----


form hide_write.

new-page print on

line-size 160

  • line-count 58

no-title

no-heading

destination 'LOCL'

immediately ' '

new list identification 'X'

no dialog.

set blank lines on.

endform. " hide_write

&----


*& Form end_write

&----


form end_write using kunnr1.

set blank lines off.

new-page print off.

***Using Spoolid we are getting PDF formated file

spoolid = spdel-rqident = sy-spono.

spdel-sys = sy-sysid.

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

exporting

src_spoolid = spoolid

no_dialog = 'X'

importing

pdf_bytecount = pdf_fsize

tables

pdf = pdf_table

exceptions

others = 0.

***Delleting Spool request

call function 'RSPO_IDELETE_SPOOLREQ'

exporting

spoolreq = spdel

exceptions

others = 2.

***Converting PDF table line size 134 into standard list size 255

loop at pdf_table into pdf_line.

if pos = 34170.

perform attach.

endif.

stuff+pos(134) = pdf_line.

add 134 to pos.

endloop.

if not ( stuff is initial ).

perform attach.

endif.

clear pdf_line.

clear pdf_table[].

describe table i_att lines tab_lines.

i_pack_list-transf_bin = 'X'.

i_pack_list-head_start = '1'.

i_pack_list-head_num = '1'.

i_pack_list-body_start = '1'.

i_pack_list-body_num = tab_lines.

i_pack_list-doc_type = 'PDF'.

i_pack_list-obj_name = 'LedgerMail'.

concatenate fmon '-' gjah into i_pack_list-obj_descr.

*i_pack_list-obj_descr = '2092-Oct03'.

i_pack_list-obj_langu = 'E'.

i_pack_list-doc_size = tab_lines * 255.

append i_pack_list.

***Data for receivers list

loop at it_inad where kunnr eq kunnr1.

i_receivers-receiver = it_inad-smtp.

i_receivers-rec_type = 'U'.

i_receivers-rec_date = sy-datum.

i_receivers-express = 'X'.

i_receivers-com_type = 'INT'.

i_receivers-notif_del = 'X'.

append i_receivers.

endloop.

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = i_doc_data

  • PUT_IN_OUTBOX = ' '

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

tables

packing_list = i_pack_list

object_header = i_header

contents_bin = i_att

contents_txt = i_contents

receivers = i_receivers

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

.

refresh i_att. clear i_att.

refresh i_receivers. clear i_receivers.

delete i_pack_list where doc_type = 'PDF'.

*refresh i_header.

*refresh i_contents.

*clear i_doc_data.

endform. " end_write

&----


*& Form doc_data

&----


form doc_data using fmondest v_gjahrt.

gjah = v_gjahrt.

fmon = fmondest.

***Data for Document Data

i_doc_data-obj_name = 'LedgerMail'.

concatenate 'Customer Ledger for : ' fmondest gjah

into i_doc_data-obj_descr separated by space.

i_doc_data-obj_langu = 'E'.

i_doc_data-obj_prio = '1'.

i_doc_data-no_change = 'X'.

i_doc_data-doc_size = '5101'.

***Data for Packing list

i_pack_list-head_start = '1'.

i_pack_list-head_num = '1'.

i_pack_list-body_start = '1'.

i_pack_list-body_num = '20'.

i_pack_list-doc_type = 'RAW'.

i_pack_list-obj_langu = 'E'.

append i_pack_list.

***Data for Header

i_header-line = 'Header'. append i_header.

***Data for contents

i_contents-line = 'Dear Customer,'. append i_contents.

i_contents-line = ' '. append i_contents.

concatenate 'Please find your enclosed Ledger for the month of : '

fmondest gjah into i_contents-line separated by space.

append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = 'This is a computer generated document and does not

require a signature.'. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = 'Note : If you do not have Acrobat Reader please click

on the below link.'. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = 'http://www.adobe.com/products/acrobat/readstep2.html'

. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

endform. " doc_data

&----


*& Form attach

&----


form attach.

clear pos.

len = strlen( stuff ).

while len > 0.

subtract 255 from len.

i_att = stuff+pos(255).

append i_att.

add 255 to pos.

endwhile.

clear pos.

clear stuff.

endform. " attach

reward if useful

regards,

ANJI

Read only

0 Likes
958

Dear,

thanks but i am not able to get anything of it

I need to do any external Configuration.

plz reply

RP

Read only

0 Likes
958

You need to check for your SCOT configuration. Scot is a transaction.

Read only

0 Likes
958

ya dear

and how it wiil connect to my ZProgram.

pls explain the scenario in detail.

thanks,

RP

Read only

0 Likes
958

Hi,

That is the basic configuration which is required to send mail outside SAP. Once that configuration is done you can send mail from your business inbox or using function module or through some other way.

You can try it on yourself, Go to transaction SCOT. In case node is there then you have to go to settings and maintain the default domain..it can be prd.wipro.com or somthing like that, you will have to search for it.then adress type will be *wipro.com (relevant to you system) and then you haveto schedules job.

1. Choose View &#61614; Jobs.

2. If there is no job scheduled, choose Job &#61614; Create.

3. Enter a job name and confirm.

4. Select the variant SAP&CONNECTALL by placing the cursor on it.

5. Choose Schedule Job.

6. Choose Schedule Periodically.

7. Enter an appropriate time period, such as 5 minutes.

8. Choose Create.

After that you can run the function module and test it.

Read only

0 Likes
958

Dear still i am not getting please tell me in detail how my ZProgram connect with SCOT and all please give all details for configuring and Code

i will definitely reward full

thanks,

RP

Read only

Former Member
0 Likes
958

Hi,

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

Check these link..

Cofiguration:

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

Sample Code:

http://www.sap-img.com/abap/sending-email-with-attachment.htm

Have a look at below code:

REPORT ZSENDEXTERNAL.

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

  • Creation of the document to be sent

  • File Name

DOC_CHNG-OBJ_NAME = 'SENDFILE'.

  • Mail Subject

DOC_CHNG-OBJ_DESCR = 'Send External Mail'.

  • Mail Contents

OBJTXT = 'Minimum bid : $250000'.

APPEND OBJTXT.

OBJTXT = 'A representation of the pictures up for auction'.

APPEND OBJTXT.

OBJTXT = 'was included as attachment.'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creation of the entry for the compressed document

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

  • Creation of the document attachment

  • (Assume that the data in OBJBIN is in BMP format)

*OBJBIN = ' \O/ '. APPEND OBJBIN.

*OBJBIN = ' | '. APPEND OBJBIN.

*OBJBIN = ' / \ '. APPEND OBJBIN.

*DESCRIBE TABLE OBJBIN LINES TAB_LINES.

*OBJHEAD = 'PICTURE.BMP'.

*APPEND OBJHEAD.

    • Creation of the entry for the compressed attachment

*OBJPACK-TRANSF_BIN = 'X'.

*OBJPACK-HEAD_START = 1.

*OBJPACK-HEAD_NUM = 1.

*OBJPACK-BODY_START = 1.

*OBJPACK-BODY_NUM = TAB_LINES.

*OBJPACK-DOC_TYPE = 'BMP'.

*OBJPACK-OBJ_NAME = 'PICTURE'.

*OBJPACK-OBJ_DESCR = 'Representation of object 138'.

*OBJPACK-DOC_SIZE = TAB_LINES * 255.

*APPEND OBJPACK.

  • Completing the recipient list

RECLIST-RECEIVER = 'youremail@sap.com'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

*RECLIST-RECEIVER = 'SAPUSERNAME'.

*RECLIST-REC_TYPE = 'P'.

*APPEND RECLIST.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

CASE SY-SUBRC.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT RECLIST.

WRITE: / RECLIST-RECEIVER(48), ':'.

IF RECLIST-RETRN_CODE = 0.

WRITE 'The document was sent'.

ELSE.

WRITE 'The document could not be sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'No authorization for sending to the specified number',

'of recipients'.

WHEN 2.

WRITE: / 'Document could not be sent to any recipient'.

WHEN 4.

WRITE: / 'No send authorization'.

WHEN OTHERS.

WRITE: / 'Error occurred while sending'.

ENDCASE.

Read only

0 Likes
958

Dear

can u help me to establish configuration for SMTP and RFC

how to define RFC and how to connect it with SMTP

thanks,

RP

Read only

0 Likes
958

all the steps are well explained (including config) in the blog link given by sunil

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

Do you have problems following that weblog?

Raja