cancel
Showing results for 
Search instead for 
Did you mean: 

Error in Mail body

former_member205842
Participant
0 Kudos

hi Experts,

                   Am trying to send mail in HTML format but am unable to send mail body (which i read from SO10) using FM read_text ..please check my code n let me know the solution..

data : wa_header type sodocchgi1.

*** Contents Data

data : it_content type standard table of solisti1 initial size 0,

        wa_content type solisti1,

*** Receivers Data

        it_receivers type standard table of somlreci1 initial size 0,

        wa_receivers type somlreci1,

        it_para type standard table of soparai1 initial size 0,

        wa_para type soparai1.

data: v_hyperlink type cfx_hyperlink.

data: v_hyperlink1 type cfx_hyperlink.

data wa_objhead type soli_tab.

data flines   type table of tline,

         w_flines like line of flines.



wa_receivers-receiver = 'notarealperson@notarealdomain.com'.

wa_receivers-rec_type = 'U'.

wa_receivers-com_type = 'INT'.

append wa_receivers to it_receivers.

clear: wa_receivers.

data : i_objpack type table of  sopcklsti1,

      w_objpack type  sopcklsti1.

wa_header-obj_prio = 1.

wa_header-priority = 1.

wa_header-obj_langu = sy-langu.

wa_header-obj_descr = 'Mail with SAP SDN link'.

concatenate 'Dear ' 'SDN ' into wa_content-line separated by ''.

append wa_content to it_content.

clear wa_content.

v_hyperlink = 'http://--------------------/sap/bc/webdynpro/sap/zcrm_post_sales'.

append wa_content to it_content.

v_hyperlink1 = '?sap-language=EN&activity_code=MDAwNw==&Duration=Mg==&partner=MjAwMDAwMDAwMg==&Object_id=MDAwMDAwMDAxMA=='.

concatenate  '<a href=' v_hyperlink v_hyperlink1 '> click here </a>'  into wa_content-line.

append wa_content to it_content.

clear wa_content.

data : i_sopcklsti1 type table of sopcklsti1,

        wa_sopcklsti1 type sopcklsti1.

wa_sopcklsti1-body_start = 'Teseting body'.

append wa_sopcklsti1 to i_sopcklsti1.

call function 'READ_TEXT'

   exporting

*   CLIENT   = SY-MANDT

     id       = 'ST'

     language = sy-langu

     name     = 'ZCRM_POST_SALES'

     object   = 'TEXT'

   tables

     lines    = flines.


loop at flines into w_flines..

   w_objtxt = w_flines-tdline .

   condense w_flines-tdline .

   append w_objtxt to i_objtxt.

   clear    w_objtxt.

endloop.

describe table i_objtxt lines v_lines_txt.

read table i_objtxt into  w_objtxt  index v_lines_txt.

wa_doc_chng-doc_size = v_lines_txt * 255.       " 255

clear w_objpack-transf_bin.

w_objpack-head_start = 1 .

w_objpack-head_num = 0 .

w_objpack-body_start = 1 .

w_objpack-body_num = v_lines_txt.

w_objpack-doc_type = 'HTM'.

append w_objpack to i_objpack.

clear w_reclist.

w_reclist-receiver wa_lead_final-smtp_addr.

w_reclist-rec_type = 'U'.

*   i_reclist-blind_copy = 'X'.

append w_reclist to i_reclist.

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

            exporting

                  document_data              = wa_doc_chng

                  put_in_outbox              = 'X'

                  commit_work                = 'X'

* IMPORTING

*   SENT_TO_ALL                      =

*   NEW_OBJECT_ID                    =

            tables

                  packing_list               = i_objpack

                  object_header              = wa_objhead

*       CONTENTS_BIN               = I_OBJBIN

                  contents_txt               = i_objtxt

                  receivers                  = i_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.

Message was edited by: Matthew Billingham - removed email address

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Dear Syed,

Please do not panic and worry about not knowing how to use cl_bcs. We are there to help you..

To make things easier for you, I have given the code below. Please try using this. I am sure you will not have any issues. In case you do, please reply to this, I shall try to solve this issue.

**************************************************************************************************************

** MAIL BODY AND SUBJECT LINE CREATION LOGIC START

**************************************************************************************************************

DATA: l_tlines     TYPE i,

          lwa_subj     TYPE tline,

          lwa_mailbody TYPE solisti1.

   FIELD-SYMBOLS : <lfs_body> TYPE tline.

   CLEAR: lwa_subj, l_tlines.

************************************************************************

** Logic to get the Subject Line

************************************************************************

*** Call FM to read text from the Standard Text

   PERFORM read_text  TABLES   i_subj

                      USING    c_st

                                    c_ru

                                    c_sub     "Standard Text name

                                   c_text

                     CHANGING  w_header.

   DESCRIBE TABLE i_subj LINES l_tlines.

   IF l_tlines IS NOT INITIAL.

*** Call FM to replace the relevant text with values.

     PERFORM text_replace TABLES i_subj

                                        USING l_tlines

                                                  w_header

                                                 sy-repid

                                                 c_x

                                                 c_x

                                                 c_x.

     READ TABLE i_subj INTO lwa_subj INDEX 1.

     IF sy-subrc EQ 0.

*** Subject of the Mail Notification

       w_subject = lwa_subj-tdline.

     ENDIF.

   ENDIF.

************************************************************************

** Logic to get the Mail Body

************************************************************************

*** Call FM to read text from the Standard Text

     PERFORM read_text  TABLES   i_body

                                       USING    c_st

                                                     c_ru

                                                     c_body1   "Standard Text Name

                                                     c_text

                                  CHANGING  w_header.

     CLEAR l_tlines.

     DESCRIBE TABLE i_body LINES l_tlines.

     IF l_tlines IS NOT INITIAL.

*** Call FM to replace the relevant text with values.

       PERFORM text_replace TABLES i_body

                                              USING l_tlines

                                                         w_header

                                                         sy-repid

                                                         c_x

                                                         c_x

                                                         c_x.

***************************************************************************

Sub routines

***************************************************************************

*****Read Text Routine.

FORM read_text  TABLES   ft_tab    STRUCTURE tline

                 USING    fu_st     TYPE thead-tdid

                               fu_ru     TYPE syst-langu

                               fu_name   TYPE thead-tdname

                               fu_obj    TYPE thead-tdobject

                 CHANGING fc_header TYPE thead.

   CALL FUNCTION 'READ_TEXT'

     EXPORTING

       id                      = fu_st

       language                = fu_ru

       name                    = fu_name

       object                  = fu_obj

     IMPORTING

       header                  = fc_header

     TABLES

       lines                   = ft_tab

     EXCEPTIONS

       id                      = 1

       language                = 2

       name                    = 3

       not_found               = 4

       object                  = 5

       reference_check         = 6

       wrong_access_to_archive = 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.

ENDFORM.                    " READ_TEXT



*** Text Replace Routine

FORM text_replace  TABLES   ft_tab         STRUCTURE tline

                    USING    fu_lines       TYPE i

                             fu_header      TYPE thead

                             fu_prgm        TYPE syst-repid

                             fu_replaceprgm TYPE c

                             fu_replacestnd TYPE c

                             fu_replacetext TYPE c.

   CALL FUNCTION 'TEXT_SYMBOL_REPLACE'

     EXPORTING

       endline          = fu_lines

       header           = fu_header

       program          = fu_prgm

       replace_program  = fu_replaceprgm

       replace_standard = fu_replacestnd

       replace_text     = fu_replacetext

     TABLES

       lines            = ft_tab.

ENDFORM.                    " TEXT_REPLACE


**************************************************************************************************************

** MAIL BODY AND SUBJECT LINE CREATION LOGIC END

**************************************************************************************************************

*****************************************************************************************************************

**** MAIL SENDING LOGIC START

*****************************************************************************************************************

DATA l_send_request     TYPE REF TO cl_bcs,

            l_document           TYPE REF TO cl_document_bcs,

            l_recipient             TYPE REF TO cl_cam_address_bcs,

            l_sender1              TYPE REF TO if_sender_bcs,

            l_bcs_exception     TYPE REF TO cx_document_bcs,

            l_addr_exception    TYPE REF TO cx_address_bcs,

            l_send_exception   TYPE REF TO cx_send_req_bcs,

            l_result                  TYPE os_boolean,

            l_oid                      TYPE sysuuid_x,

            l_sender                TYPE adr6-smtp_addr,

            l_receiver               TYPE adr6-smtp_addr,

            l_message             TYPE string.


l_sender = 'xyz@abc.com'. "You can have your logic here to decide on the Sender mail id.


*** i_adr6[] has all the mail id's to which themail has to be sent.


IF i_adr6[] IS NOT INITIAL.

     LOOP AT i_adr6 ASSIGNING <lfs_adr6>.

       TRY.

* Creates persistent send request

           l_send_request = cl_bcs=>create_persistent( ).


* Creating Document

           l_document = cl_document_bcs=>create_document( i_type = 'HTM'

                                                              i_text = i_mailbody

                                                              i_subject = w_subject ).

* Add document to send request

           CALL METHOD l_send_request->set_document( l_document ).

* Preparing the sender object

           l_sender1 = cl_cam_address_bcs=>create_internet_address(

                                                                l_sender ).

* Setting the sender

           CALL METHOD l_send_request->set_sender

             EXPORTING

               i_sender = l_sender1.

* Preparing the receiver object

           MOVE <lfs_adr6>-smtp_addr TO l_receiver.

           l_recipient = cl_cam_address_bcs=>create_internet_address(

                                                               l_receiver ).

* Adding Recipient

           CALL METHOD l_send_request->add_recipient

             EXPORTING

               i_recipient = l_recipient.

* Trigger E-Mail immediately

           l_send_request->set_send_immediately('X').

* Send E-mail

           CALL METHOD l_send_request->send(

             EXPORTING i_with_error_screen = 'X'

             RECEIVING result = l_result ).

* Obtaining Object ID

           CALL METHOD l_send_request->oid(

             RECEIVING result = l_oid ).

         CATCH cx_document_bcs INTO l_bcs_exception.

           l_message = l_bcs_exception->get_text( ).

           MESSAGE l_message TYPE c_s.

         CATCH cx_send_req_bcs INTO l_send_exception.

           l_message = l_send_exception->get_text( ).

           MESSAGE l_message TYPE c_s.

         CATCH cx_address_bcs INTO l_addr_exception.

           l_message = l_addr_exception->get_text( ).

           MESSAGE l_message TYPE c_s.

       ENDTRY.

     ENDLOOP.



Please let me know in case you have any doubts.


Regards,

Ram

former_member205842
Participant
0 Kudos

HI Rajan,

                Thanks for helping me ....it means me alot ....i used ur code but am not getting type of i_subj please let  me know ...what is the type of i_subj. Here am getting error like this i_subj is unknown.

Thanks & Regards

Syed

Former Member
0 Kudos

Hi Syed,

PFB the declaration of i_subj in addition to the other internal tables.

DATA: i_adr6     TYPE STANDARD TABLE OF t_adr6,

           i_subj     TYPE STANDARD TABLE OF tline,

           i_body     TYPE STANDARD TABLE OF tline,

           i_mailbody TYPE STANDARD TABLE OF solisti1.

Please feel free to get back to me for any details.

Regards,

Ram

Answers (3)

Answers (3)

matt
Active Contributor
0 Kudos

The first error you've made is in using the function module SO_NEW_DOCUMENT_ATT_SEND_API1 at all.  It is obsolete.

You should use the CL_BCS classes - they're much easier, and there's plenty of information and examples of how to use them on this site.

former_member205842
Participant
0 Kudos

Hi Matthew,

                    Thanks for replying, but am new for this i don't know how use cl_bcs n send mail ...n my other  issue is i have to send mail body which i declared in SO10 with hyper link ...can u please help write the code....

Thanks & Regards

Syed

Former Member
0 Kudos

This message was moderated.

matt
Active Contributor
0 Kudos

I am helping you to write the code. You must learn to use CL_BCS, and it is easy to learn to use CL_BCS by looking at the worked examples available on this very site.

You will never find this covered on a training course - you need to read the sap help and the examples, otherwise you will never learn. The fact that you are a newbie is irrelevant, as reading a few blogs and wiki articles and applying them does not need years of ABAP experience.

Also, this site is meant to help people do their job, and resolve problems they encounter. It is not a place to get training, or get spoonfed answers, or to have other people do your work for you.

former_member585060
Active Contributor
0 Kudos

Hi,

Complete mail message body not coming or its not formatted properly?

if it is not formatted properly

clear w_objpack-transf_bin.

w_objpack-head_start = 1 .

w_objpack-head_num = 0 .

w_objpack-body_start = 1 .

w_objpack-body_num = v_lines_txt.

w_objpack-doc_type = 'RAW'.                        " change to RAW from HTM.



Thanks & Regards

Bala Krishna

former_member205842
Participant
0 Kudos

HI bala

                I want to send my text body in html format ...

Regards

Syed

Former Member
0 Kudos

Hi Syed,

Try to hardcode and test once if it is working fine.

Also, please check the TYPE of i_objtxt that you have declared. It should be SOLISTI1.

Assign the values correctly:


w_objtxt-line = w_flines-tdline.

-Sowmya

former_member205842
Participant
0 Kudos

HI Sowmya,

                    Thanks for your reply, am able to send the mail but the issue is am not able to get data in mail ...when i use RAW type am getting data in mail but am not getting proper hyper link ...

Note : i don;'t want to hardcode mail body