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

A question regarding EMAIL with attachments code included

Former Member
0 Likes
1,037

Hello experts,

I've create a simple program which downloads certain files from the application server to my local drive.

now, i need to loop at those files and send an email and attach those files (everyone of them).

any suggestion on how to do so?

DATA : it_file LIKE TABLE OF sdokpath WITH HEADER LINE ,

dir_table LIKE TABLE OF sdokpath WITH HEADER LINE ,

file_count TYPE i.

DATA: it_dir TYPE TABLE OF epsfili,

wa_dir LIKE LINE OF it_dir,

lr_outlook TYPE OLE2_OBJECT,

lr_mi TYPE OLE2_OBJECT,

att type ole2_object,

atts type ole2_object,

test1 type string,

test2 type string,

g_zipper TYPE REF TO cl_abap_zip,

content_x TYPE xstring,

zip TYPE xstring.

PARAMETERS: p_pres(50) TYPE c. "source presentation directory

CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'

EXPORTING

directory = p_pres

  • filter = ''

IMPORTING

file_count = file_count

  • dir_count =

TABLES

file_table = it_file

dir_table = dir_table

EXCEPTIONS

cntl_error = 1

OTHERS = 2.

WRITE:/ 'no of files in directory is : ', file_count .

LOOP AT it_file .

concatenate p_pres it_file into test1.

WRITE:/ it_file-pathname.

CREATE OBJECT lr_outlook 'Outlook.Application'.

CALL METHOD OF lr_outlook 'CreateItem' = lr_mi

EXPORTING #1 = 0.

set property of lr_mi 'SUBJECT' = 'Smartform Output from SAP'.

*test1 = 'C:\dennistest\00069805-00000000-1.DOC'.

call method of lr_mi 'ATTACHMENTS' = atts.

CREATE OBJECT g_zipper.

CALL METHOD g_zipper->add

EXPORTING

name = test1

content = content_x.

CALL METHOD g_zipper->save

RECEIVING

zip = zip.

call method of atts 'ADD'

EXPORTING

#1 = test1.

CALL METHOD OF lr_mi 'Display'.

ENDLOOP.

here is my code of reading the files.

Hello experts,

I've create a simple program which downloads certain files from the application server to my local drive.

now, i need to loop at those files and send an email and attach those files (everyone of them).

any suggestion on how to do so?

DATA : it_file LIKE TABLE OF sdokpath WITH HEADER LINE ,

dir_table LIKE TABLE OF sdokpath WITH HEADER LINE ,

file_count TYPE i.

DATA: it_dir TYPE TABLE OF epsfili,

wa_dir LIKE LINE OF it_dir,

lr_outlook TYPE OLE2_OBJECT,

lr_mi TYPE OLE2_OBJECT,

att type ole2_object,

atts type ole2_object,

test1 type string,

test2 type string,

g_zipper TYPE REF TO cl_abap_zip,

content_x TYPE xstring,

zip TYPE xstring.

PARAMETERS: p_pres(50) TYPE c. "source presentation directory

CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'

EXPORTING

directory = p_pres

  • filter = ''

IMPORTING

file_count = file_count

  • dir_count =

TABLES

file_table = it_file

dir_table = dir_table

EXCEPTIONS

cntl_error = 1

OTHERS = 2.

WRITE:/ 'no of files in directory is : ', file_count .

LOOP AT it_file .

concatenate p_pres it_file into test1.

WRITE:/ it_file-pathname.

CREATE OBJECT lr_outlook 'Outlook.Application'.

CALL METHOD OF lr_outlook 'CreateItem' = lr_mi

EXPORTING #1 = 0.

set property of lr_mi 'SUBJECT' = 'Smartform Output from SAP'.

*test1 = 'C:\dennistest\00069805-00000000-1.DOC'.

call method of lr_mi 'ATTACHMENTS' = atts.

CREATE OBJECT g_zipper.

CALL METHOD g_zipper->add

EXPORTING

name = test1

content = content_x.

CALL METHOD g_zipper->save

RECEIVING

zip = zip.

call method of atts 'ADD'

EXPORTING

#1 = test1.

CALL METHOD OF lr_mi 'Display'.

ENDLOOP.

here is my code of reading the files.

6 REPLIES 6
Read only

Sandra_Rossi
Active Contributor
0 Likes
846

Hi,

Here you want to program Outlook to send a mail. This is not an ABAP question but a Microsoft OLE(2) question.

Instead, why don't you send the mail from SAP server directly with SMTP? (CL_BCS + SAPconnect)

BR

Sandra

Read only

0 Likes
846

The customer requested specifically using outlook.

Read only

Former Member
0 Likes
846

Hello Dennis,

please have a look at this Wiki entry from Sandra Rossi on how to send mails using the function module SO_DOCUMENT_ATT_SEND_API1:

http://wiki.sdn.sap.com/wiki/display/Snippets/Email%2bfrom%2bSAP?bc=true

You have to fill the table PACKING_LIST with your files. However, you do not necessarily have to download the documents to your local drive. Try to open the files on the application server as a DATASET:

DATA: file(32) TYPE c VALUE '/your/files/on/AL.txt',

text(32) TYPE c.

OPEN DATASET file IN TEXT MODE.

READ DATASET file INTO text.

CLOSE DATASET file.

Kind regards,

Michael Jühe

Read only

0 Likes
846

Mujehe,

the files located on a 3rd server, NETAPP.

Read only

0 Likes
846

Michael, it's not Sandra Rossi's wiki, it's not somebody's work, a wiki is the result of a community work. And in this case, I just added a link to the "Sending mail - Home page" wiki.

BR

Sandra

Read only

Sandra_Rossi
Active Contributor
0 Likes
846

So, I answer to the OLE question: I think that the first argument of the ADD method (of MailItem class) is a file path. Refer to the Microsoft Outlook Object Model documentation for more information. So you must first zip the file on the SAP server and download the zipped file on the workstation and finally add it.

Sandra