cancel
Showing results for 
Search instead for 
Did you mean: 

Change attachment content using mail forms when sending e-mail

Former Member
0 Kudos

I want to send an attachment through mail forms. The content of mail forms will change everytime. I am using  CRM_IM_CREATE_PERS_MAIL and  CRM_IM_SEND_PERSONALIZED_MAIL to send email. Please suggest how to change the content of attachment

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member210661
Active Contributor
0 Kudos

hi Ritu Goel,

here we have a Class CL_DOCUMENT_BCS this is  Used for attachment and also for creating the body of the mail.

In this class there is a method add_attachment.

this method has few importing parameters.

i_attachment_type: This is same as the i_type of the CREATE_DOCUMENT method.

1 i_attachment_subject: The name of the attachment.

2 i_attachment_size: Size of the attachment which is also an optional parameter.

3 i_language: The language of the attachment which is an optional parameter.

4 i_attachment_text: If the created attachment content is in text format. This is an optional

parameter.

5  i_attachment_hex: If the created attachment content is in binary format. This is an optional

parameter.

Sample code to add an attachment to the created document using this method

CALL METHOD v_document->add_attachment

EXPORTING

i_attachment_type = „HTM‟ “Since it is an HTML attachment

i_attachment_subject = „HTML Attachment‟

i_att_content_text = t_html1.

Here t_html1 is a table with line of length 255 and will be having the contents which needs to be attached to the mail.

to fill attachment data u have to declare like this..

data : l_attach    TYPE bcsy_text,                " Attachment

     wa_text     TYPE soli.     " Work area for attach

* Preparing contents of attachment with Change Log

* Header line

wa_text-line+0   = 'First column'.

wa_text-line+20  = 'Second column'.

wa_text-line+40  = 'Third column'.

wa_text-line+60  = 'Fourth column'.

wa_text-line+80  = 'Fifth column'.

wa_text-line+100 = 'Sixth column'.

wa_text-line+120 = 'Seventh column'.

wa_text-line+140 = 'Eighth column'.

APPEND wa_text TO l_attach.

this is the sample program just go through this..

DATA: l_send_request TYPE REF TO cl_bcs,         " Send request

      l_body      TYPE bcsy_text,                " Mail body

      l_attach    TYPE bcsy_text,                " Attachment

      wa_text     TYPE soli,                     " Work area for attach

      l_document  TYPE REF TO cl_document_bcs,   " Mail body

      l_sender    TYPE REF TO if_sender_bcs,     " Sender address

      l_recipient TYPE REF TO if_recipient_bcs,  " Recipient

      l_size      TYPE sood-objlen,              " Size of Attachment

      c_tab       TYPE abap_char1  VALUE

                       cl_abap_char_utilities=>horizontal_tab,

      l_lines     TYPE i,                        " Lines count

      l_email     TYPE ad_smtpadr,               " Email ID

      l_extension TYPE soodk-objtp VALUE 'RAW'.  " TXT format

* Prepare mail bidy

APPEND 'Test Mail by Sree' TO l_body.

* Preparing contents of attachment with Change Log

* Header line

wa_text-line+0   = 'First column'.

wa_text-line+20  = 'Second column'.

wa_text-line+40  = 'Third column'.

wa_text-line+60  = 'Fourth column'.

wa_text-line+80  = 'Fifth column'.

wa_text-line+100 = 'Sixth column'.

wa_text-line+120 = 'Seventh column'.

wa_text-line+140 = 'Eighth column'.

APPEND wa_text TO l_attach.

CLEAR : wa_text.

* Populate the data part

wa_text-line+0   = '111111111'.

wa_text-line+20  = '222222222'.

wa_text-line+40  = '333333333'.

wa_text-line+60  = '333333333'.

wa_text-line+80  = '444444444'.

wa_text-line+100 = '555555555'.

wa_text-line+120 = '666666666'.

wa_text-line+140 = '777777777'.

APPEND wa_text TO l_attach.

CLEAR : wa_text.

wa_text-line+0   = 'aaaaaaaaa'.

wa_text-line+20  = 'bbbbbbbbb'.

wa_text-line+40  = 'ccccccccc'.

wa_text-line+60  = 'ddddddddd'.

wa_text-line+80  = 'eeeeeeeee'.

wa_text-line+100 = 'fffffffff'.

wa_text-line+120 = 'ggggggggg'.

wa_text-line+140 = 'hhhhhhhhh'.

APPEND wa_text TO l_attach.

CLEAR : wa_text.

l_lines = LINES( l_attach ).

l_size = l_lines * 255.

* Creates persistent send request

l_send_request = cl_bcs=>create_persistent( ).

* Craete document for mail body

l_document = cl_document_bcs=>create_document(

             i_type    = 'RAW'

             i_text    = l_body

             i_subject = 'Mail send as attachment' ).

* Add attchment

CALL METHOD l_document->add_attachment

  EXPORTING

    i_attachment_type    = l_extension

    i_attachment_subject = 'My attachment'

    i_attachment_size    = l_size

    i_att_content_text   = l_attach.

* Add the document to send request

CALL METHOD l_send_request->set_document( l_document ).

* Sender addess

l_sender = cl_sapuser_bcs=>create( sy-uname ).

CALL METHOD l_send_request->set_sender

  EXPORTING

    i_sender = l_sender.

* Recipient address

l_email = 'srinivas.karri@marvelrealtors.com'.

l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).

* Add recipient address to send request

CALL METHOD l_send_request->add_recipient

  EXPORTING

    i_recipient  = l_recipient

    i_express    = 'X'

    i_copy       = ' '

    i_blind_copy = ' '

    i_no_forward = ' '.

* Trigger E-Mail immediately

l_send_request->set_send_immediately( 'X' ).

* Send mail

CALL METHOD l_send_request->send( ).

COMMIT WORK.

if you want to know more about this go through this link..

Thanks & Regards,

Srinivas.