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

problem with email attachment

Former Member
0 Likes
1,400

hi experts!

i am using the fm SO_NEW_DOCUMENT_ATT_SEND_API1 to send an email w/ attachment to various recipients. When i test the program, i receive an attachment in text format. but i want my attachment to be in excel format. please give me an idea how to do solve this problem. thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
426

Check this link.

http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm

Regards,

Susmitha

Mark helpful answers.

3 REPLIES 3
Read only

Former Member
0 Likes
426

check thread same question...

Read only

Former Member
0 Likes
427

Check this link.

http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm

Regards,

Susmitha

Mark helpful answers.

Read only

Former Member
0 Likes
426

Check the link below for how it works......

/people/thomas.jung3/blog/2004/09/07/sending-e-mail-from-abap--version-46d-and-lower--api-interface

Also check the Code below

REPORT test.


DATA: att_size TYPE i,                             " att Size
      att_itab_size TYPE i,                        " Attachment size
      mailtxt_size TYPE i.                         " Text in mail size

DATA:
it_mailpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, " Dist details
it_mailhead LIKE solisti1   OCCURS  1 WITH HEADER LINE," Header data
it_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,   " Rec List
it_mailtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,    " Mail Text
it_att_data LIKE solisti1 OCCURS 0 WITH HEADER LINE,   " Attachment data
it_doc_att LIKE sodocchgi1.                          " Attri of new doc

* Text in the mail.
it_mailtxt-line  = ' This is a test mail,  Line Number--1'.
APPEND it_mailtxt.
it_mailtxt-line = ' This is a test mail,  Line Number--2' &
                  ' This is a test mail,  Line Number--2'.
APPEND it_mailtxt.
it_mailtxt-line = ' This is a test mail,  Line Number--3' &
                  ' This is a test mail,  Line Number--3' &
                  ' This is a test mail,  Line Number--3'.
APPEND it_mailtxt.
DESCRIBE TABLE it_mailtxt LINES mailtxt_size.

* Create the att File
concatenate 'Attachment Line Number 1' space into it_att_data-line.

APPEND it_att_data.
concatenate 'Attachment Line Number 2' space into it_att_data-line.
APPEND it_att_data.
concatenate 'Attachment Line Number 3' space into it_att_data-line.
APPEND it_att_data.
DESCRIBE TABLE it_att_data LINES att_itab_size.


* Attributes of new doc
CONCATENATE 'Attach' space 'mail'
            INTO it_doc_att-obj_descr SEPARATED BY space.
it_doc_att-sensitivty = 'F'.
it_doc_att-doc_size   = mailtxt_size * 255.

* Create Pack to text in mail body.
it_mailpack-transf_bin   = space.
it_mailpack-head_start   = 1.
it_mailpack-head_num     = 0.
it_mailpack-body_start   = 1.
it_mailpack-body_num     = mailtxt_size.
it_mailpack-doc_type     = 'RAW'.
APPEND it_mailpack.

* Create Pack for Attach.
it_mailpack-transf_bin   = 'X'.
it_mailpack-head_start   = 1.
it_mailpack-head_num     = 1.
it_mailpack-body_start   = 1.
it_mailpack-body_num     = att_itab_size.
it_mailpack-doc_type     = 'XLS'.
CONCATENATE 'My' space 'Attachment' INTO it_mailpack-obj_descr.
it_mailpack-doc_size     = att_itab_size * 255.
APPEND it_mailpack.


it_reclist-receiver   = 'yourname@domain.com'.
it_reclist-express    = 'X'.
it_reclist-rec_type   = 'U'.
it_reclist-notif_del  = 'X'. " request delivery notification
it_reclist-notif_ndel = 'X'. " request not delivered notification
APPEND it_reclist.

* Call FM to send email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
     EXPORTING
          document_data              = it_doc_att
          put_in_outbox              = 'X'
     TABLES
          packing_list               = it_mailpack
          object_header              = it_mailhead
          contents_txt               = it_mailtxt
          contents_bin               = it_att_data
          receivers                  = it_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 sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

Cheers,

Thomas.