Skip to Content
0
Former Member
Oct 18, 2006 at 08:52 AM

Email trigger thru SAP

33 Views

Hi,

I have got a code from one of the forums topics on how to trigger mails from SAP to outlook express inbox.

Well but when i am trying to execute the code,the code is throwing an exception "Document not sent" .

I runa report program for DMS where i have data for different types of Doc's in an internal table.

Now i want to send e-mails according to Doc type.Please help find the solution to the problem.

Manually if i try send the mail thru SCOT T-code,its working so guess my all configuration is okay .

I am also attaching the sample code for reference.

TABLES : DRAW.

DATA : ITAB_DRAW LIKE DRAW OCCURS 0 WITH HEADER LINE .

data : date type sy-datum.

data: itcpo like itcpo,

tab_lines like sy-tabix.

  • Variables for EMAIL functionality

data: maildata like sodocchgi1.

data: mailpack like sopcklsti1 occurs 2 with header line.

data: mailhead like solisti1 occurs 1 with header line.

data: mailbin like solisti1 occurs 10 with header line.

data: mailtxt like solisti1 occurs 10 with header line.

data: mailrec like somlrec90 occurs 0 with header line.

data: solisti1 like solisti1 occurs 0 with header line.

perform send_form_via_email.

************************************************************************

  • FORM SEND_FORM_VIA_EMAIL *

************************************************************************

form send_form_via_email.

clear: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.

refresh: mailtxt, mailbin, mailpack, mailhead, mailrec.

  • Creation of the document to be sent File Name

maildata-obj_name = 'TEST'.

  • Mail Subject

maildata-obj_descr = 'ALERT : DOC GETTING EXPIRED'.

  • Mail Contents

mailtxt-line = 'Please find the attached file'.

append mailtxt.

  • Prepare Packing List

perform prepare_packing_list.

  • Set recipient - email address here!!!

mailrec-receiver = 'dsm-ltil@essar.com'.

mailrec-rec_type = 'U'.

append mailrec.

date = sy-datum + 1 .

SELECT * FROM DRAW INTO TABLE ITAB_DRAW

WHERE VRLDAT = date.

  • Sending the document

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = maildata

put_in_outbox = ' '

tables

packing_list = mailpack

object_header = mailhead

contents_bin = mailbin

contents_txt = mailtxt

receivers = mailrec

exceptions

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

others = 99.

endform.

************************************************************************

  • Form PREPARE_PACKING_LIST

************************************************************************

form prepare_packing_list.

clear: mailpack, mailbin, mailhead.

refresh: mailpack, mailbin, mailhead.

describe table mailtxt lines tab_lines.

read table mailtxt index tab_lines.

maildata-doc_size = ( tab_lines - 1 ) * 255 + strlen( mailtxt ).

  • Creation of the entry for the compressed document

clear mailpack-transf_bin.

mailpack-head_start = 1.

mailpack-head_num = 0.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'RAW'.

append mailpack.

mailhead = 'TEST.TXT'.

append mailhead.

  • File 1

mailbin = 'This is file 1'.

append mailbin.

describe table mailbin lines tab_lines.

mailpack-transf_bin = 'X'.

mailpack-head_start = 1.

mailpack-head_num = 1.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'TXT'.

mailpack-obj_name = 'TEST1'.

mailpack-obj_descr = 'Subject'.

mailpack-doc_size = tab_lines * 255.

append mailpack.

*File 2

mailbin = 'This is file 2'.

append mailbin.

data: start type i.

data: end type i.

start = tab_lines + 1.

describe table mailbin lines end.

mailpack-transf_bin = 'X'.

mailpack-head_start = 1.

mailpack-head_num = 1.

mailpack-body_start = start.

mailpack-body_num = end.

mailpack-doc_type = 'TXT'.

mailpack-obj_name = 'TEST2'.

mailpack-obj_descr = 'Subject'.

mailpack-doc_size = tab_lines * 255.

append mailpack.

endform.

Also wanted to know whether on how can i send e-mails to more than one person and also if i can put one of the names in cc list .

Thanx'

Akhil