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

Attachments in mail

Former Member
0 Likes
1,307

Hi,

I need to develop a transaction which can be used to send mail to customers with attachments.After i have to display that communication (subject , body and attachments ) as report.

Can anyone tell how to accept the attachments , how to store them and how to show.

Hi,

I need to develop a transaction which can be used to send mail to customers with attachments.After i have to display that communication (subject , body and attachments ) as report.

Can anyone tell how to accept the attachments , how to store them and how to show.

9 REPLIES 9
Read only

jaideepsharma
Active Contributor
0 Likes
1,256

Hi,

You can add attachments to email using Function module SO_NEW_DOCUMENT_ATT_SEND_API1. Also, go through the link below.

[Send External Mail with attachement |http://wiki.sdn.sap.com/wiki/display/ABAP/SendExternalMailwithattachement]

KR Jaideep,

Read only

0 Likes
1,256

Hi,

Above FM is used to take the data in an internal table and email that as an attachment.

But i have to accept the PDF document from pc as attachment , and i have to send that pdf as an attachment in email.

Read only

0 Likes
1,256

You need to upload the PDF data into an internal table and then send that data using the FM mentioned above.

Ansari

Read only

0 Likes
1,256

Hi Venu...

Check the below links...it should solve your problem the requirement is similar.

Read only

0 Likes
1,256

Hi vin,

I am using GUI_UPLOAD to accept the pdf file from pc. But the data in internal table is not in pdf data.

when i try to send the same as attachment , the attachment is not opening.

PDF file is external one of user.

How to convert that.

Read only

0 Likes
1,256

Hi,

After using GUI_UPLOAD to upload the PDF from the pc to internal table, you cannot directly use this internal table to send the E-mail. You will have to convert this internal table data back to PDF and then send it as a attachment through E-mail.

Check this thread to convert internal table to PDF

{;

Regards,

vikranth

Read only

Former Member
0 Likes
1,256

HI,

use this FM ...

F4IF_INT_TABLE_VALUE_REQUEST

this FM is used to select the documents from local PC and stores it in the internal table.

And pass that internal table into the above FM in the appropriate field...i.e..

SO_NEW_DOCUMENT_ATT_SEND_API1 .

Regards

Kiran

Read only

Former Member
0 Likes
1,256

Hi Venugopal,

Check out the tutorial titled 'Send Email with attachment of any format' at Saptechnical.com.

Regards,

Goutham.

Read only

Former Member
0 Likes
1,256

Hi Find the below code.

1. copy the code which containd one include also.

Name of the include: ZAMI_INCLFOR_MAIL

This program can be used for any type attachment.

REPORT  zsend_mail.
INCLUDE zami_inclfor_mail.

*----------------------------------------------------------------------
* DATA
*----------------------------------------------------------------------
DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.
DATA : file_name TYPE string.
DATA : path LIKE pcfile-path.
DATA : extension(5) TYPE c.
DATA : name(100) TYPE c.

*----------------------------------------------------------------------
* SELECTION SCREEN
*----------------------------------------------------------------------

PARAMETERS : receiver TYPE somlreci1-receiver LOWER CASE.
PARAMETERS : p_file LIKE rlgrap-filename OBLIGATORY.
PARAMETERS : spoolno LIKE tsp01-rqident.

*----------------------------------------------------------------------
* AT SELECTION SCREEN
*----------------------------------------------------------------------


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CLEAR p_file.

  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = p_file.

*----------------------------------------------------------------------
* START-OF-SELECTION
*----------------------------------------------------------------------

START-OF-SELECTION.
  PERFORM ml_customize USING 'Tst' 'Testing'.
  PERFORM ml_addrecp USING receiver 'U'.
  IF spoolno IS INITIAL.
    PERFORM upl.
  ENDIF.
  IF NOT spoolno IS INITIAL.
    CLEAR p_file.
    PERFORM ml_spooltopdf USING spoolno.
    p_file = 'C:\ATTACH.PDF'.
    PERFORM upl.
    PERFORM delete_file.
  ENDIF.
  PERFORM doconv TABLES itab objbin.
  PERFORM ml_prepare USING 'X' extension name.
  PERFORM ml_dosend.

*----------------------------

  SUBMIT rsconn01
  WITH mode EQ 'INT'
  AND RETURN.

*----------------------------------------------------------------------
* FORM
*----------------------------------------------------------------------

FORM upl.

  file_name = p_file.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = file_name
      filetype                = 'BIN'
    TABLES
      data_tab                = itab.

  path = file_name.

  CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
  EXPORTING
  complete_filename = path
  IMPORTING
  extension = extension
  name = name
  .
ENDFORM. "upl

code of include.

-


*&---------------------------------------------------------------------*
*&  Include           ZAMI_INCLFOR_MAIL                                *
*&---------------------------------------------------------------------*


DATA: docdata LIKE sodocchgi1,
      objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
      objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
      objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
      objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
      objhex LIKE solix OCCURS 10 WITH HEADER LINE,
      reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
DATA: tab_lines TYPE i,
      doc_size TYPE i,
      att_type LIKE soodk-objtp.
DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.


*----------------------------------------------------------
* FORM
*----------------------------------------------------------
FORM ml_customize USING objname objdesc.

*----------- Clear Variables
  CLEAR docdata.
  REFRESH objpack.
  CLEAR objpack.
  REFRESH objhead.
  REFRESH objtxt.
  CLEAR objtxt.
  REFRESH objbin.
  CLEAR objbin.
  REFRESH objhex.
  CLEAR objhex.
  REFRESH reclist.
  CLEAR reclist.
  REFRESH listobject.
  CLEAR listobject.
  CLEAR tab_lines.
  CLEAR doc_size.
  CLEAR att_type.

*--------- Set Variables
  docdata-obj_name = objname.
  docdata-obj_descr = objdesc.


ENDFORM. "ml_customize

*----------------------------------------------------------
* FORM
*----------------------------------------------------------
FORM ml_addrecp USING preceiver prec_type.

  CLEAR reclist.
  reclist-receiver = preceiver.
  reclist-rec_type = prec_type.
  APPEND reclist.


ENDFORM. "ml_customize


*----------------------------------------------------------
* FORM
*----------------------------------------------------------
FORM ml_addtxt USING ptxt.

  CLEAR objtxt.
  objtxt = ptxt.
  APPEND objtxt.

ENDFORM. "ml_customize


*----------------------------------------------------------
* FORM
*----------------------------------------------------------
FORM ml_prepare USING bypassmemory whatatt_type whatname.

  IF bypassmemory = ''.
*--------- Fetch List From Memory

    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = listobject
      EXCEPTIONS
        OTHERS     = 1.

    IF sy-subrc <> 0.
      MESSAGE ID '61' TYPE 'E' NUMBER '731'
      WITH 'LIST_FROM_MEMORY'.
    ENDIF.

    CALL FUNCTION 'TABLE_COMPRESS'
* IMPORTING
* COMPRESSED_SIZE =
    TABLES
    in = listobject
    out = objbin
    EXCEPTIONS
    OTHERS = 1
    .
    IF sy-subrc <> 0.
      MESSAGE ID '61' TYPE 'E' NUMBER '731'
      WITH 'TABLE_COMPRESS'.
    ENDIF.

  ENDIF.

* -----------
* Header Data
* Already Done Thru FM
* -----------


* -----------
* Main Text
* Already Done Thru FM
* -----------

* -----------
* Packing Info For Text Data
* -----------

  DESCRIBE TABLE objtxt LINES tab_lines.
  READ TABLE objtxt INDEX tab_lines.
  docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
  CLEAR objpack-transf_bin.
  objpack-head_start = 1.
  objpack-head_num = 0.
  objpack-body_start = 1.
  objpack-body_num = tab_lines.
  objpack-doc_type = 'TXT'.
  APPEND objpack.


* -----------
* Packing Info Attachment
* -----------

  att_type = whatatt_type..
  DESCRIBE TABLE objbin LINES tab_lines.
  READ TABLE objbin INDEX tab_lines.
  objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).
  objpack-transf_bin = 'X'.
  objpack-head_start = 1.
  objpack-head_num = 0.
  objpack-body_start = 1.
  objpack-body_num = tab_lines.
  objpack-doc_type = att_type.
  objpack-obj_name = 'ATTACHMENT'.
  objpack-obj_descr = whatname.
  APPEND objpack.


* -----------
* Receiver List
* Already done thru fm
* -----------


ENDFORM. "ml_prepare

*----------------------------------------------------------
* FORM
*----------------------------------------------------------

FORM ml_dosend.

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
  document_data = docdata
  put_in_outbox = 'X'
  commit_work = 'X' "used from rel. 6.10
  TABLES
  packing_list = objpack
  object_header = objhead
  contents_bin = objbin
  contents_txt = objtxt
  receivers = reclist
  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
  .

  IF sy-subrc <> 0.
    MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
    WITH docdata-obj_name.
  ENDIF.

ENDFORM. "ml_customize

*----------------------------------------------------------
* FORM
*----------------------------------------------------------
FORM ml_spooltopdf USING whatspoolid.

  DATA : pdf LIKE tline OCCURS 0 WITH HEADER LINE.
  DATA: datei TYPE string VALUE 'C:\ATTACH.PDF'.
  data: bin_filesize type i.

*-------------- Call Function

  CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
    EXPORTING
      src_spoolid         = whatspoolid
    TABLES
      pdf                 = pdf
    EXCEPTIONS
      err_no_otf_spooljob = 1
      OTHERS              = 12.


  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      bin_filesize = bin_filesize
      filename     = datei
      filetype     = 'BIN'
    CHANGING
      data_tab     = pdf[].

*------------- Convert
  PERFORM doconv TABLES pdf objbin.

ENDFORM. "ml_spooltopdf

*----------------------------------------------------------
* FORM
*----------------------------------------------------------

FORM doconv TABLES
mypdf STRUCTURE tline
outbin STRUCTURE solisti1.

*-------- Data
  DATA : pos TYPE i.
  DATA : len TYPE i.

*------------ Loop And Put Data

  LOOP AT mypdf.
    pos = 255 - len.
    IF pos > 134. "length of pdf_table
      pos = 134.
    ENDIF.
    outbin+len = mypdf(pos).
    len = len + pos.
    IF len = 255. "length of out (contents_bin)
      APPEND outbin.
      CLEAR: outbin, len.
      IF pos < 134.
        outbin = mypdf+pos.
        len = 134 - pos.
      ENDIF.
    ENDIF.
  ENDLOOP.
  IF len > 0.
    APPEND outbin.
  ENDIF.

ENDFORM. "doconv

*&---------------------------------------------------------------------*
*&      Form  DELETE_FILE
*&---------------------------------------------------------------------*
form DELETE_FILE .
CALL FUNCTION 'GUI_DELETE_FILE'
  EXPORTING
    file_name       = 'C:\ATTACH.PDF'
 EXCEPTIONS
   FAILED          = 1
   OTHERS          = 2
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform.                    " DELETE_FILE