01-14-2005 7:56 AM
Hi All,
My requirement is to send the contents of an internal table as an attachment via mail to an external mail address.
I am working in SAP version 3.1H.
Would anybody provide a sample code of how to do so?
regards,
Paul
01-14-2005 8:20 AM
See also https://www.sdn.sap.com/sdn/collaboration.sdn?node=linkFnode6-1&contenttype=url&content=https://
There is also this excellent weblog by Thomas Jung.
/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface
I'm not sure if all of these will work with your SAP version though.
01-14-2005 10:51 AM
Hi,
If you require small example you can also have look on the
following sample code which will post internal table data as attachment. Please not email address has to be customised in the <b>SAP usermaintaince.</b>
FORM send_mail.
it_doc_chng-obj_name = text-016.
it_doc_chng-obj_descr = text-016.
DESCRIBE TABLE it_objtxt LINES g_lines.
READ TABLE it_objtxt INDEX g_lines.
it_objpack-doc_size = ( g_lines - 1 ) * 255 + STRLEN( it_objtxt ).
it_objpack-doc_type = 'RAW'.
APPEND it_objpack.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-transf_bin = 'X'.
it_objpack-body_num = g_lines.
it_objpack-doc_type = 'RAW'.
it_objpack-obj_name = 'ATTACHMENT'.
it_objpack-obj_descr = g_file.
APPEND it_objpack.
completing the recipient list
SORT it_vmail.
DELETE ADJACENT DUPLICATES FROM it_vmail.
IF l_client NE 'P'.
it_reclist-receiver = p_email.
it_reclist-express = 'X'.
it_reclist-rec_type = 'U'.
APPEND it_reclist.
ELSE.
LOOP AT it_vmail.
it_reclist-receiver = it_vmail-smtp_addr.
it_reclist-express = 'X'.
it_reclist-rec_type = 'U'.
APPEND it_reclist.
ENDLOOP.
ENDIF.
it_rec_mail[] = it_reclist[].
IF NOT p_copy IS INITIAL.
it_reclist-receiver = p_copy.
it_reclist-express = 'X'.
it_reclist-copy = 'X'.
it_reclist-rec_type = 'U'.
APPEND it_reclist.
ENDIF.
CLEAR it_download[].
it_download[] = it_objtxt[].
**********Sending the mail with attachment*****************
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_MAPI'
EXPORTING
document_data = it_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_objpack
contents_bin = it_objtxt
contents_txt = it_objtxt
receivers = it_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
CASE sy-subrc.
WHEN 0.
IF p_update = 'X'.
PERFORM reference_update.
ENDIF.
PERFORM down_load.
WRITE:/01 text-019.
SKIP.
LOOP AT it_rec_mail.
FORMAT COLOR 5 INTENSIFIED OFF.
WRITE:/01 text-010,20 it_rec_mail-receiver.
ENDLOOP.
ULINE.
WHEN 1.
WRITE: / text-012.
WHEN 2.
WRITE: / text-013.
WHEN 4.
WRITE: / text-014.
WHEN OTHERS.
WRITE: / text-015.
ENDCASE.
REFRESH:it_objpack,
it_objtxt,
it_reclist,
it_rec_mail.
CLEAR:it_objpack,
it_objtxt,
it_reclist,
g_lines,
it_rec_mail.
ENDFORM. " send_mail
Regards
Suresh Babu Karanam