cancel
Showing results for 
Search instead for 
Did you mean: 

sending E-mail with attachment within a loop not working.

Former Member
0 Kudos

Hi,

I'm trying to send e-mails with attachment to multiple users with "subject & an attachment" within an ITAB loop.

SUBJECT for each mail to corresponding user is being sent properly.

But ATTACHMENT contents are not being sent properly.

1st ATTACHMENT contents are going to 2nd user(supposed to go to 1st user) & 2nd ATTACHMENT contents are going to 3rd user etc..

in almost all attempts, last ATTACHMENT contents within the loop were delivered properly to the last user.

As a test, I'm debugging by sending with same "SUBJECT" & "ATTACHMENT CONTENTS". still it's not working.

Following is the code for sending mail with same "SUBJECT" & "ATTACHMENT CONTENTS".

I even refreshed the file contents for each record within the ITAB. Greatly appreciate any help.

assume that ITAB has a field GROUP with values 501, 502, 503 & 504.

SUBJECT is the subject of e-mail & DIST_LIST is the e-mail id of the corresponding user.

DATA:

MAIL_FILE(20) TYPE C,

MAIL_TEXT(200) TYPE C,

COMMAND(512) TYPE C,

DIST_LIST(425) TYPE C,

SUBJECT(60) TYPE C.

DATA: BEGIN OF ITAB OCCURS 0.

DATA GROUP LIKE /BI0/PGRP-GRP.

DATA: END OF ITAB.

LOOP AT ITAB.

SUBJECT = ITAB-GROUP.

IF ITAB-GROUP = '501'.

DIST_LIST = 'mailto501@ABC.com'.

ENDIF.

IF ITAB-GROUP = '502'.

DIST_LIST = 'mailto502@ABC.com'.

ENDIF.

IF ITAB-GROUP = '503'.

DIST_LIST = 'mailto503@ABC.com'.

ENDIF.

IF ITAB-GROUP = '504'.

DIST_LIST = 'mailto504@ABC.com'.

ENDIF.

clear MAIL_FILE.

clear MAIL_TEXT.

UNASSIGN <FILE1>.

CONCATENATE '/tmp/' SY-UNAME '.txt' INTO MAIL_FILE.

TRANSLATE MAIL_FILE TO LOWER CASE.

OPEN DATASET MAIL_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

MAIL_TEXT = ITAB-GROUP.

TRANSFER MAIL_TEXT TO MAIL_FILE LENGTH 200.

CLOSE DATASET MAIL_FILE.

clear MAIL_TEXT.

CONCATENATE '< ' MAIL_FILE INTO MAIL_TEXT SEPARATED BY SPACE.

ASSIGN MAIL_TEXT TO <FILE1>.

*Create UNIX MAIL Command

CONCATENATE 'mailx -s'

'"' SUBJECT '"' '"' DIST_LIST '"' <FILE1>

INTO COMMAND SEPARATED BY SPACE.

  • Send the E-mail

CALL FUNCTION 'RFC_REMOTE_EXEC'

DESTINATION 'SERVER_EXEC'

EXPORTING

COMMAND = COMMAND

EXCEPTIONS

OTHERS = 04.

ENDLOOP.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi, the code looks no problem.

But the attach file name is the same in every loop.

Have you check the content of them?

Former Member
0 Kudos

Hi Zhenglin,

thanks for your reply.

Now, it's working after I changed attachment file name (user name) with ITAB-GROUP.

but, I'm not clear on why it was not working even if the file name is same in every loop, as I'm unassigning the file contents and loading new contents at the start of each loop.

anyhow, it's working and many thanks for your help.

Answers (0)