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: 

E-mail as text attachment

Former Member
0 Kudos

Hi,

I want to send E-Mail as a .txt attachment.

I tried using FM SO_DOCUMENT_SEND_API1, but its giving the sy-subrc = 2 (I.E document_not_sent) .

Is 4.5B supports the text attachment ?

is any configration requried?

we have development and Quality clients this below code execuated in develpment sucessfully but when iam trying to test in quality client its throwing the error ( document_not_sent)

Below is my code


*--Data declearation
 DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE.
 DATA: OBJHEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
 DATA: OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
 DATA: OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
 DATA: RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.
 DATA: DOC_CHNG LIKE SODOCCHGI1.
 DATA: TAB_LINES LIKE SY-TABIX.
 DATA: L_MSG(100) TYPE C.
 
* Creation of the document to be sent
DOC_CHNG-OBJ_NAME = 'Z2318S1B01'.
DOC_CHNG-OBJ_DESCR = EMSUBJ .
OBJTXT = 'your report from apple vacations is enclosed as
          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 ).
 
* Creation of 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.
 
* Creation of the document attachment
LOOP AT IT_ATTACHMENT.
OBJBIN = IT_ATTACHMENT-EMAIL.
APPEND OBJBIN.
CLEAR OBJBIN.
ENDLOOP.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
 
OBJHEAD = 'Airport Mainfest.txt'.
APPEND OBJHEAD.
 
* Creation of the entry for the compressed attachment
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'BMP'.
OBJPACK-OBJ_NAME = 'ANLAGE'.
OBJPACK-OBJ_DESCR = 'Representation of object 138'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
 
* Completing the recipient list
TRANSLATE EMAILID-LOW TO LOWER CASE.
RECLIST-RECEIVER = EMAILID-LOW.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
 
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
     EXPORTING
          DOCUMENT_DATA              =  DOC_CHNG
         PUT_IN_OUTBOX              =  '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
         DOCUMENT_TYPE_NOT_EXIST    = 3
         OPERATION_NO_AUTHORIZATION = 4
         PARAMETER_ERROR            = 5
         X_ERROR                    = 6
         ENQUEUE_ERROR              = 7
         OTHERS                     = 8.
 
 IF SY-SUBRC = 0.
  LOOP AT RECLIST.
    IF RECLIST-RETRN_CODE = 0.
        CONCATENATE RECLIST-RECEIVER ':'
                    'The document was sent' INTO L_MSG.
   MESSAGE S656 WITH L_MSG.
    ELSE.
    CONCATENATE RECLIST-RECEIVER ':'
                   'The document was sent' INTO L_MSG.
       MESSAGE E656 WITH L_MSG.
    ENDIF.
  ENDLOOP.
 ELSE.
        CONCATENATE RECLIST-RECEIVER ':'
        'error occurred in sending mail' INTO L_MSG.
       MESSAGE S656 WITH L_MSG.
 ENDIF.

Thanks

Vikranth khimavath

2 REPLIES 2

Former Member
0 Kudos

vikranth,

Compare below code with your ......

REPORT zmbundal_email_out .

DATA BEGIN OF object_hd_change. "SAPoffice: object definition,

INCLUDE STRUCTURE sood1. "change attributes

DATA END OF object_hd_change.

DATA BEGIN OF object_content OCCURS 5. "SAPoffice: Single List with

INCLUDE STRUCTURE solisti1. "Column Length 255

DATA END OF object_content.

DATA BEGIN OF rec_table OCCURS 1. "SAPoffice: recipient with

INCLUDE STRUCTURE soos1. "attributes

DATA END OF rec_table.

  • Build email recipient table...........................................

CLEAR rec_table.

rec_table-sel = 'X'.

rec_table-recesc = 'B'.

rec_table-recesc = 'U'.

rec_table-recnam = 'U-'.

rec_table-recextnam = 'destination@yahoo.com'.

rec_table-adr_name = 'destination@yahoo.com'.

rec_table-sndex = 'X'.

rec_table-sndpri = '1'.

rec_table-mailstatus = 'E'.

rec_table-SNDSPO = 442355.

rec_table-SNDCP = 'X'.

COLLECT rec_table.

*.Email.content.........................................................

object_content = 'dannyboy baboy'. APPEND object_content.

object_content = 'dannyboy pogi'. APPEND object_content.

object_content = 'dannyboy fagg*t'. APPEND object_content.

*...Subject.Line........................................................

object_hd_change-objnam = 'Test email'.

object_hd_change-objdes = ' Email for Baboy'.

  • Send Email............................................................

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

object_hd_change = object_hd_change

object_type = 'RAW'

outbox_flag = 'X'

TABLES

objcont = object_content

receivers = rec_table

EXCEPTIONS

active_user_not_exist = 1

communication_failure = 2

component_not_available = 3

folder_not_exist = 4

folder_no_authorization = 5

forwarder_not_exist = 6

note_not_exist = 7

object_not_exist = 8

object_not_sent = 9

object_no_authorization = 10

object_type_not_exist = 11

operation_no_authorization = 12

owner_not_exist = 13

parameter_error = 14

substitute_not_active = 15

substitute_not_defined = 16

system_failure = 17

too_much_receivers = 18

user_not_exist = 19

originator_not_exist = 20

x_error = 21

OTHERS = 22.

*...SAPconnect..........................................................

SUBMIT rsconn01 "SAPconnect Start Send Process

WITH mode EQ '*'

WITH output EQ ''

TO SAP-SPOOL

DESTINATION 'LOCAL'

IMMEDIATELY ' '

KEEP IN SPOOL 'X'

WITHOUT SPOOL DYNPRO

AND RETURN.

Pls. Mark if useful

Former Member
0 Kudos

HI,

This program will allowed you to send email with attachment.

  • First, specify the attachment file from your local hardisk and execute.

  • Next, specify the sender email address and click the send button.

*report y_cr17_mail.

data method1 like sy-ucomm.

data g_user like soudnamei1.

data g_user_data like soudatai1.

data g_owner like soud-usrnam.

data g_receipients like soos1 occurs 0 with header line.

data g_document like sood4 .

data g_header like sood2.

data g_folmam like sofm2.

data g_objcnt like soli occurs 0 with header line.

data g_objhead like soli occurs 0 with header line.

data g_objpara like selc occurs 0 with header line.

data g_objparb like soop1 occurs 0 with header line.

data g_attachments like sood5 occurs 0 with header line.

data g_references like soxrl occurs 0 with header line.

data g_authority like sofa-usracc.

data g_ref_document like sood4.

data g_new_parent like soodk.

data: begin of g_files occurs 10 ,

text(4096) type c,

end of g_files.

data : fold_number(12) type c,

fold_yr(2) type c,

fold_type(3) type c.

parameters ws_file(4096) type c default 'c:\debugger.txt'.

  • Can me any file fromyour pc ....either xls or word or ppt etc ...

g_user-sapname = sy-uname.

call function 'SO_USER_READ_API1'

exporting

user = g_user

  • PREPARE_FOR_FOLDER_ACCESS = ' '

importing

user_data = g_user_data

  • EXCEPTIONS

  • USER_NOT_EXIST = 1

  • PARAMETER_ERROR = 2

  • X_ERROR = 3

  • OTHERS = 4

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

fold_type = g_user_data-outboxfol+0(3).

fold_yr = g_user_data-outboxfol+3(2).

fold_number = g_user_data-outboxfol+5(12).

clear g_files.

refresh : g_objcnt,

g_objhead,

g_objpara,

g_objparb,

g_receipients,

g_attachments,

g_references,

g_files.

method1 = 'SAVE'.

g_document-foltp = fold_type.

g_document-folyr = fold_yr.

g_document-folno = fold_number.

g_document-objtp = g_user_data-object_typ.

*g_document-OBJYR = '27'.

*g_document-OBJNO = '000000002365'.

*g_document-OBJNAM = 'MESSAGE'.

g_document-objdes = 'sap-img.com testing by program'.

g_document-folrg = 'O'.

*g_document-okcode = 'CHNG'.

g_document-objlen = '0'.

g_document-file_ext = 'TXT'.

g_header-objdes = 'sap-img.com testing by program'.

g_header-file_ext = 'TXT'.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = sy-uname

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header

  • FOLMEM_DATA =

  • RECEIVE_DATA =

.

  • File from the pc to send...

method1 = 'ATTCREATEFROMPC'.

g_files-text = ws_file.

append g_files.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = g_owner

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header

.

method1 = 'SEND'.

g_receipients-recnam = 'MK085'.

g_receipients-recesc = 'B'.

g_receipients-sndex = 'X'.

append g_receipients.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = g_owner

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header.

*-- End of Program

Hope this helps.

Reward if helpful.

Regards,

Sipra