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: 

MULTIPLE attachments for email

Former Member
0 Kudos
2,907

Hi guys,

I am using FM <b>SO_NEW_DOCUMENT_ATT_SEND_API1</b> for sending email. Presently it works fine, albeit I need to add functionality for sending <b>more than one attachment</b>

In the program, the spool is first converted to pdf and the pdf is sent as an attachment. Could you guys suggest a way to incorporate multiple attachments.

Thanks!

below is the code snippet.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = gd_spool_nr

no_dialog = ' '

dst_device = 'LOCL'

IMPORTING

pdf_bytecount = gd_bytecount

TABLES

pdf = it_pdf_output.

CHECK sy-subrc = 0.

  • Transfer the 132-long strings to 255-long strings

LOOP AT it_pdf_output.

TRANSLATE it_pdf_output USING ' ~'.

CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.

ENDLOOP.

TRANSLATE gd_buffer USING '~ '.

DO.

it_mess_att = gd_buffer.

APPEND it_mess_att.

SHIFT gd_buffer LEFT BY 255 PLACES.

IF gd_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
443

Hi,

Check the below code.

Here OBJBIN contain the content of 2 attachments.

OBJPACK contain the entry for mail body and attachments. First entry must be for the mail body and then for attachments.

So first write all the content of all attachment file to OBJBIN and at time of putting entry for attachment in OBJPACK, u need to specify the starting and number of line for that attachment in OBJBIN.

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

DATA: TAB_LINES1 LIKE SY-TABIX.

  • Creating the document to be sent

DOC_CHNG-OBJ_NAME = 'OFFER'.

DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.

OBJTXT = 'Reserve price : $250000'.

APPEND OBJTXT.

OBJTXT = 'A reproduction of the painting to be auctioned'.

APPEND OBJTXT.

OBJTXT = 'is enclosed as an attachment.'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creating the entry for the compressed document

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

  • Creating the document attachment

*

*content for attachment 1.

*================================

OBJBIN = 'ABC'. APPEND OBJBIN.

OBJBIN = 'ABC '. APPEND OBJBIN.

OBJBIN = 'ABC '. APPEND OBJBIN.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

*================================

  • Creating the entry for the compressed attachment

  • Entry for attachment 1.

*================================

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1. “ starting line for attachment 1 in OBJBIN object

OBJPACK-BODY_NUM = TAB_LINES. “ total number of line for the attachment 1 in OBJBIN object.

OBJPACK-DOC_TYPE = 'TXT'.

OBJPACK-OBJ_NAME = 'ATTACHMENT1'.

OBJPACK-OBJ_DESCR = 'ABC'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK..

*================================

*content for attachment 1.

*================================

OBJBIN = 'XYZ'. APPEND OBJBIN.

OBJBIN = 'XYZ '. APPEND OBJBIN.

OBJBIN = 'XYZ '. APPEND OBJBIN.

*================================

  • Entry for attachment 1.

*================================

DESCRIBE TABLE OBJBIN LINES TAB_LINES1.

TAB_LINES1 = TAB_LINES1 - TAB_LINES.

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = TAB_LINES + 1. “ starting line for attachment 1 in OBJBIN object

OBJPACK-BODY_NUM = TAB_LINES1. “ total number of line for the attachment 1 in OBJBIN object.

OBJPACK-DOC_TYPE = 'TXT'.

OBJPACK-OBJ_NAME = 'ATTACHMENT2'.

OBJPACK-OBJ_DESCR = 'XYZ'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK..

  • Entering names in the distribution list

RECLIST-RECEIVER = 'vikram.rawal@lntinfotech.com'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'developer'.

RECLIST-REC_TYPE = 'B'.

APPEND RECLIST.

WRITE:/ 'BEFORE SENDING MAIL'.

LOOP AT RECLIST.

WRITE:/ RECLIST-RECEIVER.

ENDLOOP.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

This example simply shows how u can send mail with multiple attachment so now u can modify it with ur requirement.

Reward points if found helpful..

Regards,

Vikram Rawal

4 REPLIES 4

Former Member
0 Kudos
443

Hi

Refer this link:

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/excel-attachment-for-sending-email-exte...

Reward points if found helpful..

Cheers,

Chandra Sekhar.

VikasB
Active Participant
0 Kudos
443

Hi,

Try out for FM SO_DOCUMENT_SEND_API1

Regards,

Vikas

Plz reward if helpful

Former Member
0 Kudos
444

Hi,

Check the below code.

Here OBJBIN contain the content of 2 attachments.

OBJPACK contain the entry for mail body and attachments. First entry must be for the mail body and then for attachments.

So first write all the content of all attachment file to OBJBIN and at time of putting entry for attachment in OBJPACK, u need to specify the starting and number of line for that attachment in OBJBIN.

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

DATA: TAB_LINES1 LIKE SY-TABIX.

  • Creating the document to be sent

DOC_CHNG-OBJ_NAME = 'OFFER'.

DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.

OBJTXT = 'Reserve price : $250000'.

APPEND OBJTXT.

OBJTXT = 'A reproduction of the painting to be auctioned'.

APPEND OBJTXT.

OBJTXT = 'is enclosed as an attachment.'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creating the entry for the compressed document

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

  • Creating the document attachment

*

*content for attachment 1.

*================================

OBJBIN = 'ABC'. APPEND OBJBIN.

OBJBIN = 'ABC '. APPEND OBJBIN.

OBJBIN = 'ABC '. APPEND OBJBIN.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

*================================

  • Creating the entry for the compressed attachment

  • Entry for attachment 1.

*================================

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1. “ starting line for attachment 1 in OBJBIN object

OBJPACK-BODY_NUM = TAB_LINES. “ total number of line for the attachment 1 in OBJBIN object.

OBJPACK-DOC_TYPE = 'TXT'.

OBJPACK-OBJ_NAME = 'ATTACHMENT1'.

OBJPACK-OBJ_DESCR = 'ABC'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK..

*================================

*content for attachment 1.

*================================

OBJBIN = 'XYZ'. APPEND OBJBIN.

OBJBIN = 'XYZ '. APPEND OBJBIN.

OBJBIN = 'XYZ '. APPEND OBJBIN.

*================================

  • Entry for attachment 1.

*================================

DESCRIBE TABLE OBJBIN LINES TAB_LINES1.

TAB_LINES1 = TAB_LINES1 - TAB_LINES.

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = TAB_LINES + 1. “ starting line for attachment 1 in OBJBIN object

OBJPACK-BODY_NUM = TAB_LINES1. “ total number of line for the attachment 1 in OBJBIN object.

OBJPACK-DOC_TYPE = 'TXT'.

OBJPACK-OBJ_NAME = 'ATTACHMENT2'.

OBJPACK-OBJ_DESCR = 'XYZ'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK..

  • Entering names in the distribution list

RECLIST-RECEIVER = 'vikram.rawal@lntinfotech.com'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'developer'.

RECLIST-REC_TYPE = 'B'.

APPEND RECLIST.

WRITE:/ 'BEFORE SENDING MAIL'.

LOOP AT RECLIST.

WRITE:/ RECLIST-RECEIVER.

ENDLOOP.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

This example simply shows how u can send mail with multiple attachment so now u can modify it with ur requirement.

Reward points if found helpful..

Regards,

Vikram Rawal

0 Kudos
443

Thanks a bunch Vikram!

Works perfect.