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: 

Sending Mail with attachment

Former Member
0 Kudos
135

Hi Friends,

I have to send mail to users with an attachment. File Format will be Zip file. We have to read the file from the application server and send email.

Thanks

Suganya

4 REPLIES 4

Former Member
0 Kudos
9

Hi

Refer to the below program code.

http://www.sap-img.com/abap/sending-email-with-attachment.htm

Regards

Divya

0 Kudos
9

Comon guys -- this is 2008 -- why are you still using / posting links to old deprecated stuff

As I've previously posted DON'T MAKE STUFF TOO COMPLICATED

KISS Keep It Short and Simple,

Anybody who even THINKS of using SAP INBOX type folders etc etc should not be allowed to use ABAP ever again. !!!!!

In these days of OO and Netweaver you should be using BCS. Note of course your SAP system must have the e-mail facility available (SAPCONNECT).




program  zemailtest_with_attachment.

* This example shows how to send
*   - a simple text provided in an internal table of text lines
*   - and an attached MS word document provided in internal table
*   - to some internet email address.
*

class ca_sapuser_bcs     definition load.
class cl_cam_address_bcs definition load.

data: send_request       type ref to cl_bcs.
data: text               type bcsy_text.
data: binary_content     type solix_tab.
data: document           type ref to cl_document_bcs.
data: sender             type ref to cl_sapuser_bcs.
data: recipient          type ref to if_recipient_bcs.
data: bcs_exception      type ref to cx_bcs.
data: sent_to_all        type os_boolean.

data: document_data like  sofolenti1,
      doc_id    like sofolenti1-doc_id,
      cont_hex  like solix occurs 100,
      cont_text type soli_tab,
      cont_hex1 like solix occurs 10.
data: attachment type ref to if_document_bcs.



start-of-selection.

    perform main.


*---------------------------------------------------------------------*
*       FORM main                                                     *
*---------------------------------------------------------------------*
form main.

  try.
*     -------- create persistent send request ------------------------
      send_request = cl_bcs=>create_persistent( ).

*     -------- create and set document with attachment ---------------
*     create document from internal table with text
      append 'Hello world!' to text.
      document = cl_document_bcs=>create_document(
                    i_type    = 'RAW'
                    i_text    = text
                    i_length  = '12'
                    i_subject = 'main document created by whatever  ' ).

*     create attachment
      clear text.
      append 'This is the attachment text!' to text.    "#EC NOTEXT
      attachment = cl_document_bcs=>create_document(
                                    i_type    = 'RAW'
                                    i_text    = text
                                    i_length  = '11'
                                    i_subject = 'attachment...' ).

*     add (existing) attachment to main document
      call method document->add_document_as_attachment
        exporting
          im_document     = attachment
          .


*     add document to send request
      call method send_request->set_document( document ).

*     --------- add recipient (e-mail address) -----------------------
*     create recipient
      recipient = cl_cam_address_bcs=>create_internet_address(    " your email address  
                                        'youremailaddres here ' ).

*     add recipient with its respective attributes to send request
      call method send_request->add_recipient
        exporting
          i_recipient  = recipient
          i_express    = 'X'.

*     ---------- send document ---------------------------------------
      send_request->send_request->set_link_to_outbox( 'X' ).

      call method send_request->send(
        exporting
          i_with_error_screen = 'X'
        receiving
          result              = sent_to_all ).
      if sent_to_all = 'X'.
        write text-003.
      endif.

      commit work.


* -----------------------------------------------------------
* *                     exception handling
* -----------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* -----------------------------------------------------------
  catch cx_bcs into bcs_exception.
    write: 'error  resultes.'(001).
    write: 'messtype:'(002), bcs_exception->error_type.
    exit.

  endtry.

endform.

Cheers

jimbo

0 Kudos
9

Hi James,

hats off to you!!!I just tried using your sample program and it works so good!!

I just had one more question regarding the format of the attachment...I need to send the attachment in form of PDF or EXCEL...then what is the value i should pass to i_type ???

BR,

SRM Tech.