2007 Aug 28 3:33 PM
Hi all,
How do I send an <b>attachment</b> with the e-mail to a distribution list?
I am using the FMs <b>SO_DLI_EXPAND</b> and <b>SO_OBJECT_SEND</b> to expand the distribution list and send mail to the distribution list respectively.I am getting the contents of the file in the email that is being sent. The file is being extracted from UNIX.
However, the contents of the file has to go as an attachment.
Please assist.
Thanks and regards,
Anishur
2007 Aug 28 3:40 PM
your packing list is not properly built
personnaly I don't use the SO_OBJECT_SEND because it is very low-level, I prefer using FM set SO_*_API1 to create message, add attachment(s) then send it
2007 Aug 28 3:44 PM
Here is a sample program which creates a text file and attachs to email and sends to a distribution list.
report zrich_0003.
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.
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 = 'Subject'.
* Mail Contents
mailtxt-line = 'Here is your file'.
append mailtxt.
* Prepare Packing List
perform prepare_packing_list.
* To send to distribution list
mailrec-receiver = 'TESTDSTLIST'.
mailrec-rec_type = 'C'. " or P for Private
append mailrec.
* 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.
endform.
Regards,
RIch Heilman
2007 Aug 28 3:46 PM
Hello,
You can do it like this...using SapScript:
REPORT YMAIL.
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 = 'Subject'.
Mail Contents
MAILTXT-LINE = 'Here is your file, would you check it?'.
APPEND MAILTXT.
Prepare Packing List
PERFORM PREPARE_PACKING_LIST.
BREAK gpulido.
Set recipient - email address here!!!
<b>*MAILREC-RECEIVER = 'xxxxxxx@gmail.com'.
MAILREC-RECEIVER = 'xxxxxxxx@yahoo.com'.
MAILREC-REC_TYPE = 'U'.</b>
APPEND MAILREC.
Set recipient - email address here!!!
*MAILREC-RECEIVER = 'BGIRALDO'.
*MAILREC-REC_TYPE = 'B'.
*APPEND MAILREC.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = MAILDATA
PUT_IN_OUTBOX = 'X'
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.
submit rsconn01 with mode = 'INT' and return.
CASE SY-SUBRC.
WHEN 0.
WRITE: / 'Result of the send process:'.
LOOP AT MAILREC.
WRITE: / mailrec-RECEIVER(48), ':'.
IF mailrec-RETRN_CODE = 0.
WRITE 'sent successfully'.
ELSE.
WRITE 'not sent'.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / 'no authorization to send to the specified number of'
.
WHEN 2.
WRITE: / 'document could not be sent to any of the recipients!'.
WHEN 4.
WRITE: / 'no authorization to send !'.
WHEN OTHERS.
WRITE: / 'error occurred during sending !'.
ENDCASE.
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.
Creation of the document attachment
This form gets the OTF code from the SAPscript form.
If you already have your OTF code, I believe that you may
be able to skip this form. just do the following code, looping thru
your SOLISTI1 and updating MAILBIN.
PERFORM GET_OTF_CODE.
LOOP AT SOLISTI1.
MOVE-CORRESPONDING SOLISTI1 TO MAILBIN.
APPEND MAILBIN.
ENDLOOP.
DESCRIBE TABLE MAILBIN LINES TAB_LINES.
MAILHEAD = 'TEST.OTF'.
APPEND MAILHEAD.
Creation of the entry for the compressed attachment
MAILPACK-TRANSF_BIN = 'X'.
MAILPACK-HEAD_START = 1.
MAILPACK-HEAD_NUM = 1.
MAILPACK-BODY_START = 1.
MAILPACK-BODY_NUM = TAB_LINES.
MAILPACK-DOC_TYPE = 'OTF'.
MAILPACK-OBJ_NAME = 'TEST'.
MAILPACK-OBJ_DESCR = 'Subject'.
MAILPACK-DOC_SIZE = TAB_LINES * 255.
APPEND MAILPACK.
ENDFORM.
***********************************************************************
Form GET_OTF_CODE
***********************************************************************
FORM GET_OTF_CODE.
DATA: BEGIN OF OTF OCCURS 0.
INCLUDE STRUCTURE ITCOO .
DATA: END OF OTF.
DATA: ITCPO LIKE ITCPO.
DATA: ITCPP LIKE ITCPP.
CLEAR ITCPO.
ITCPO-TDGETOTF = 'X'.
Start writing OTF code
CALL FUNCTION 'OPEN_FORM'
EXPORTING
FORM = 'YSEND_MAIL'
LANGUAGE = SY-LANGU
OPTIONS = ITCPO
DIALOG = ' '
EXCEPTIONS
OTHERS = 1.
CALL FUNCTION 'START_FORM'
EXCEPTIONS
ERROR_MESSAGE = 01
OTHERS = 02.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
WINDOW = 'MAIN'
EXCEPTIONS
ERROR_MESSAGE = 01
OTHERS = 02.
Close up Form and get OTF code
CALL FUNCTION 'END_FORM'
EXCEPTIONS
ERROR_MESSAGE = 01
OTHERS = 02.
MOVE-CORRESPONDING ITCPO TO ITCPP.
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = ITCPP
TABLES
OTFDATA = OTF
EXCEPTIONS
OTHERS = 1.
Move OTF code to structure SOLI form email
CLEAR SOLISTI1. REFRESH SOLISTI1.
LOOP AT OTF.
SOLISTI1-LINE = OTF.
APPEND SOLISTI1.
ENDLOOP.
Reward points if helpful.
Thanks
Message was edited by:
Pattan Naveen