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

mail attachment problem

Former Member
0 Likes
558

Hi,

i like to send mail with .TXT file attached.

the problem is that the contenent of the file is pasted in the mail body and not in a separated file!

please help

A+

Ihsen ABROUG

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
532

I tested Rich Heilman sample program,

it's sending the document as a separated text file while the receiver is sap inbox.

but when the receiver is internet email adress it's not working!

A+

Ihsen ABROUG

6 REPLIES 6
Read only

Former Member
0 Likes
532

The problem is related to packinglist table ...please correct that and it would send out as an attachment.

Sample code

data: IS_DOCDATA type SODOCCHGI1,

IS_RECEIVERS type SOMLRECI1,

IS_RECEIVERS_COPY type SOMLRECI1,

IT_RECEIVERS type table of SOMLRECI1,

IS_CONTENT type SOLISTI1,

IT_CONTENT type table of SOLISTI1,

*500369789+

l_txt(255) type c,

lt_objpack TYPE TABLE OF sopcklsti1 WITH HEADER LINE,

lt_objhead TYPE TABLE OF solisti1 WITH HEADER LINE,

lt_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE,

l_tab_lines TYPE i,

l_att_type LIKE soodk-objtp.

*500369789+

IS_DOCDATA-OBJ_NAME = 'MAIL'.

IS_DOCDATA-PRIORITY = 5.

IS_DOCDATA-OBJ_LANGU = SY-LANGU.

IS_DOCDATA-NO_CHANGE = 'X'.

IS_DOCDATA-OBJ_DESCR = SY-CPROG.

loop at IT_MESSAGE into IS_MESSAGE.

clear : IS_CONTENT, l_txt. "500369789+

move is_message-line to l_txt. "500369789+

  • move IS_MESSAGE-LINE to IS_CONTENT-LINE. "500369789-

move l_txt to IS_CONTENT-LINE. "500369789+

append IS_CONTENT to IT_CONTENT.

endloop.

*---select_email_address

select single

EMAILADDR

CCEMAILADDR

into (IS_RECEIVERS-RECEIVER, IS_RECEIVERS_COPY-RECEIVER)

from ZGL_EMAILCTRL

where IDENT = ''

and ZPROGRAM = 'Z_L_SO_CREA'

and ACTIVE = 'X'.

if IS_RECEIVERS-RECEIVER is not initial.

IS_RECEIVERS-REC_TYPE = 'U'.

IS_RECEIVERS_COPY-REC_TYPE = 'U'.

IS_RECEIVERS_COPY-COPY = 'X'.

append IS_RECEIVERS to IT_RECEIVERS.

append IS_RECEIVERS_COPY to IT_RECEIVERS.

*500369789+

lt_objhead-line = 'USA Order Report'.

append lt_objhead.

<b>DESCRIBE TABLE lt_objhead LINES l_tab_lines.

CLEAR lt_objpack-transf_bin.

lt_objpack-doc_size = STRLEN( lt_objhead ).

lt_objpack-head_start = 1.

lt_objpack-head_num = 1.

lt_objpack-body_start = 1.

lt_objpack-body_num = 1.

lt_objpack-doc_type = 'RAW'.

APPEND lt_objpack.

l_att_type = 'RAW'.

DESCRIBE TABLE it_content LINES l_tab_lines.

READ TABLE it_content into is_content INDEX l_tab_lines.

lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255.

lt_objpack-doc_size = lt_objpack-doc_size + STRLEN( is_content ).

lt_objpack-transf_bin = 'X'.

lt_objpack-head_start = 1.

lt_objpack-head_num = 2.

lt_objpack-body_start = 1.

lt_objpack-body_num = l_tab_lines.

lt_objpack-doc_type = l_att_type.

lt_objpack-obj_name = 'ATTACHMENT'.

concatenate 'Usa' SY-DATUM6(2) SY-DATUM4(2) into

lt_objpack-obj_descr. "#EC *

APPEND lt_objpack.</b> CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = IS_DOCDATA

commit_work = 'X'

TABLES

<b>packing_list = lt_objpack</b>

  • object_header = lt_objhead

contents_txt = lt_objhead

contents_bin = it_content

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.

Message was edited by: Anurag Bankley

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
532

Here is a sample program showing how to attach multiple .txt files to an email.



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.


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'.
  append mailtxt.

* Prepare Packing List
  perform prepare_packing_list.

* Set recipient - email address here!!!
  mailrec-receiver = 'you@yourcompany.com'.
  mailrec-rec_type  = 'U'.
  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.



*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.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
533

I tested Rich Heilman sample program,

it's sending the document as a separated text file while the receiver is sap inbox.

but when the receiver is internet email adress it's not working!

A+

Ihsen ABROUG

Read only

0 Likes
532

Did you my sample code...or paste yours..

Please check if you not missed the commit_work parameter as it is not defined in Rich's code.

COMMIT_WORK

Read only

Former Member
0 Likes
532

Hi,

set reciver list as "B' to send to internet address

mailrec-receiver = 'you@yourcompany.com'.

mailrec-rec_type = 'B'.

append mailrec.

regards

amole

Read only

Former Member
0 Likes
532

Thanks problem solved with the commit_work!