Application Development 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: 

2 attachment in an email

Former Member
0 Kudos

Hi All,

Am working in smartforms,

Is that possible to attach 2 pdf file in an email and send it.

If possible please help me out.

Ashok...

1 REPLY 1

Former Member
0 Kudos

Hello,

Check this sample code.


report ztest.
 
 
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.

Hope this will helps you,

Cheers,

Vasanth