06-13-2006 2:39 PM
Hi all,
we have requirement to send an e-mail from a report (might be a batch job) , is there any standard fucntion module to do this .
or any other procedure ?.
Thanks in Advance,
Kishore Kumar Yerra.
06-13-2006 2:41 PM
Try the FM: SO_NEW_DOCUMENT_ATT_SEND_API1.
Please, mark ALL useful answers if it helps you.
Regards,Felipe Cunha [FpdC]
06-13-2006 2:43 PM
HI,
Use FM <b>SO_NEW_DOCUMENT_ATT_SEND_API1</b>
Call the FM to post the message to SAPMAIL
call function <b>'SO_NEW_DOCUMENT_ATT_SEND_API1'</b>
exporting
document_data = gd_doc_data
put_in_outbox = 'X'
importing
sent_to_all = gd_sent_all
tables
packing_list = it_packing_list
contents_txt = it_message
receivers = it_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.
Check these out for the same
http://www.sapdevelopment.co.uk/reporting/email/email_mbody.htm
http://www.sap-img.com/abap/sending-email-with-attachment.htm
06-13-2006 2:46 PM
Here is a sample program which will allow you to use one of two methods. You will also need to run the SEND program to send the emails. The program is RSCONN01.
* In order to send a mail from someone
* other than the current user, you must
* use the funciton module SO_OBJECT_SEND
* and give parameters to the ORGINATOR
*
* ORIGINATOR = me@mycompany.com'.
* ORIGINATOR_TYPE = 'U'.
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.
* For SO_OBJECT_SEND
data: maildata2 type sood1.
data: mailrec2 type table of soos1 with header line.
parameters: p_api radiobutton group grp1 default 'X',
p_obj radiobutton group grp1.
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.
if p_api = 'X'.
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.
elseif p_obj = 'X'.
* Move the receivers to the other reciever table for SO_OBJECT_SEND
loop at mailrec.
mailrec2-recextnam = mailrec-receiver.
mailrec2-recesc = 'E'.
mailrec2-sndpri = '1'.
mailrec2-sndart = 'INT'.
mailrec2-mailstatus = 'E'.
append mailrec2.
endloop.
maildata2-objnam = maildata-obj_name .
maildata2-objdes = maildata-obj_descr .
maildata2-objla = maildata-obj_langu .
call function 'SO_OBJECT_SEND'
exporting
object_hd_change = maildata2
object_type = 'RAW'
outbox_flag = 'X'
originator = 'donotreply@yorktwn.com'
originator_type = 'U'
tables
objcont = mailtxt
objhead = mailtxt
receivers = mailrec2
exceptions
object_not_sent = 15
object_type_not_exist = 17
operation_no_authorization = 21
parameter_error = 23
too_much_receivers = 73
others = 1000.
endif.
You can put the SEND program at the end of this program.
Submit RSCONN01 with mode = 'INT' and return.
Regards,
Rich Heilman
06-13-2006 2:45 PM
Hai
Check the following Code
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.
DATA L_NUM(3).
Creation of the document to be sent
File Name
DOC_CHNG-OBJ_NAME = 'SENDFILE'.
Mail Subject
DOC_CHNG-OBJ_DESCR = 'Delivered Mail'.
Mail Contents
OBJTXT = 'Object text'.
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
LOOP AT ITAB_DATA.
CONCATENATE ITAB_DATA-PRODUCTOR
ITAB_DATA-VBELN
ITAB_DATA-POSNR
ITAB_DATA-MATNR INTO OBJBIN.
APPEND OBJBIN.
ENDLOOP.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'ORDERS'.
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 = 'TXT'.
OBJPACK-OBJ_NAME = 'WEBSITE'.
OBJPACK-OBJ_DESCR = 'ORDERS.TXT'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
Completing the recipient list
target recipent
clear RECLIST.
RECLIST-RECEIVER = 'test@here.com'.
RECLIST-EXPRESS = 'X'.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
copy recipents
clear RECLIST.
RECLIST-RECEIVER = 'secondtest@here.com'.
RECLIST-EXPRESS = 'X'.
RECLIST-REC_TYPE = 'U'.
RECLIST-COPY = 'X'.
APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
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.
Thanks & regards
Sreeni
06-13-2006 2:47 PM
06-13-2006 2:53 PM
Hi kishore,
check this sample code:
DATA : tab_lines TYPE i.
DATA : var_receiver LIKE sadrud.
EXPORT TO FM
DATA : wa_docu_data LIKE sodocchgi1.
IMPORT FROM FM
DATA : flag_sent_to_all LIKE sonv-flag.
DATA : obj_id LIKE sofolenti1-object_id.
TABLES TO FM
DATA : obj_header LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
DATA : rec_list LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
DATA : obj_txt LIKE solisti1 OCCURS 0 WITH HEADER LINE.
START-OF-SELECTION.
var_receiver-address = <email@removed>'.
obj_txt-line = 'This is the sent Document'.
APPEND obj_txt.
CLEAR obj_txt.
DESCRIBE TABLE obj_txt LINES tab_lines.
READ TABLE obj_txt INDEX tab_lines.
BREAK-POINT.
wa_docu_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( obj_txt ).
wa_docu_data-obj_name = 'TESTING'.
wa_docu_data-obj_descr = 'This is Test Mail'.
wa_docu_data-proc_type = 'R'.
wa_docu_data-proc_name = 'Z34_MAIL_TEST'.
wa_docu_data-proc_syst = '*'.
wa_docu_data-proc_clint = '*'.
wa_docu_data-to_do_out = 'X'.
wa_docu_data-sensitivity = 'O'.
obj_header-transf_bin = ' '.
obj_header-head_start = 1.
obj_header-head_num = 0.
obj_header-body_start = 1.
obj_header-body_num = tab_lines.
obj_header-doc_type = 'RAW'.
APPEND obj_header.
CLEAR obj_header.
BREAK-POINT.
rec_list-receiver = var_receiver-address.
rec_list-rec_type = 'U'.
rec_list-express = 'X'.
rec_list-com_type = 'INT'.
rec_list-notif_del = 'X'.
APPEND rec_list.
CLEAR rec_list.
BREAK-POINT.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_docu_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = flag_sent_to_all
new_object_id = obj_id
TABLES
packing_list = obj_header
OBJECT_HEADER =
CONTENTS_BIN =
contents_txt = obj_txt
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
receivers = rec_list
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.
BREAK-POINT.
WRITE : / , 'Object Created' , obj_id,50 'SENT TO ALL' ,
flag_sent_to_all.
LOOP AT rec_list.
WRITE 😕 , 'status' , rec_list-retrn_code,
/ , 'Sent to' , rec_list-receiver.
ENDLOOP.
regards,
keerthi.
06-13-2006 3:07 PM
Hi Kishore,
Refer the following links.
sending mail with attachment
http://www.sap-img.com/abap/sending-email-with-attachment.htm
sending mail with attachment report in background
http://www.sap-img.com/abap/sending-mail-with-attachment-report-in-background.htm
sending external mail thru SAP
http://www.sap-img.com/fu016.htm
<b>Reward all helpful answers and close the thread.</b>
08-25-2006 11:02 AM
Thanks friends........
But the thing is where we have to check the execution...
only in that mail id or other transation is there.
Previously I used Function module as "custom function module'and checked in "SOSD" transaction.......
iam getting data as same but formation is not comming...
if i go with concatenate seperated by K.( k TYPE X ) IS NOT SUPPRTING... Plz check it...
08-25-2006 12:43 PM
you can check the mail status in SOST transaction.
this will have all mail status whether they sent/wait etc...
Regards
srikanth
08-25-2006 12:35 PM