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

Send email via html template solution

carlos_zhang3
Participant
0 Likes
817

Dear Guru ,

I am writing an abap program that can send the 'HTML' email to external user ( such as : GMAIL , YAHOO ) ...

Up to now , everything is fine .... But i am looking for a solution that is it possibile to use a HTML template for that ?

For example :

I have one HTML file , like that :


<body>
  <table>
     <tr><td>&name</td></tr>
     <tr><td>&address</td></tr>
  </table>

And in my abap program i will fill my username ( sy-uname ) and address ( zaddress ) to this HTML file and then send to the external user ...

Any good idea for that ? My idea is very stupid that put this file to internal table and then check it line by line ....

Thanks .

Best Regards,

Carlos

5 REPLIES 5
Read only

Former Member
0 Likes
607

You can use html tag like this ;

data : wa_objtxt TYPE solisti1,

it_objtxt TYPE TABLE OF solisti1,

wa_objtxt = '<body>'.

APPEND wa_objtxt TO it_objtxt.

wa_objtxt = '<table id="Table_01" align="center" width="700" border="0" cellpadding="0" cellspacing="0">'.

APPEND wa_objtxt TO it_objtxt.

wa_objtxt = '<tr>'.

APPEND wa_objtxt TO it_objtxt.

wa_objtxt = '<td>'.

APPEND wa_objtxt TO it_objtxt.

wa_objtxt = '<img src= >'.

APPEND wa_objtxt TO it_objtxt.

wa_objtxt = '</td>'.

APPEND wa_objtxt TO it_objtxt.

wa_objtxt = '</tr>'.

APPEND wa_objtxt TO it_objtxt.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = wa_docdata

PUT_IN_OUTBOX = ' '

sender_address = '...'

sender_address_type = 'INT'

commit_work = 'X'

TABLES

packing_list = it_objpack

contents_txt = it_objtxt

receivers = it_reclist

Read only

0 Likes
607

Dear cagatay ,

Thanks .

This is the way we are using now . but it seems very diffcult to handle the complex html template ...

Imagine we have 100 html template files need to be sent and we will spend a lot of time on this hardcoding ....

Thanks again .

Best Regards,

Carlos

Read only

0 Likes
607

Here i share my abap code if someone internet for this topic :


FUNCTION Z_BCAPPLYTEMPLATE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(FILE) TYPE  CHAR255
*"  TABLES
*"      PARAMETERS STRUCTURE  ZTMPLSTRU
*"      CONTEXT STRUCTURE  ZTMPLSTRU
*"----------------------------------------------------------------------
* This function can read a template file that storage in the application server
* And then replace the "^" charater to some parameters .
* Sometimes use for the HTML format email sending
*"----------------------------------------------------------------------
* By Carlos

* Defined vars
  DATA : BEGIN OF IT_READ OCCURS 0.
         INCLUDE STRUCTURE ZTMPLSTRU .
  DATA : END OF IT_READ .

  DATA : V_LENLEFT LIKE SY-FDPOS .
  DATA : V_PARAMETER TYPE CHAR200 .
  DATA : V_IDX TYPE I .

  V_IDX = 1 .
  SY-SUBRC = 0 .
  OPEN DATASET : FILE FOR INPUT IN TEXT MODE ENCODING UTF-8.

  CLEAR : IT_READ[] .

* Read file
  DO.
      IF sy-subrc <> 0.
        exit.
      ENDIF.
      READ DATASET FILE INTO IT_READ.

      IF sy-subrc = 0.
        append IT_READ .
      ENDIF.
  ENDDO.


  CLOSE DATASET FILE .

* Start apply parameters

  LOOP AT IT_READ .

      CLEAR : V_LENLEFT .

      CONTEXT = IT_READ .

      WHILE sy-subrc = 0 .

            CLEAR :  V_LENLEFT .
            SEARCH CONTEXT-LINE for '^' .

            IF SY-SUBRC = 0 .
            " READ PARAMETERS
                READ TABLE PARAMETERS INDEX V_IDX  .
                  IF SY-SUBRC = 0 .
                      V_PARAMETER = PARAMETERS-LINE .
                      V_IDX = V_IDX + 1 .
                  ENDIF .

                V_LENLEFT = SY-FDPOS + STRLEN( V_PARAMETER ) - 1 .

                concatenate CONTEXT-LINE(sy-fdpos) V_PARAMETER CONTEXT-LINE+v_lenleft into CONTEXT-LINE .
            else.
                append CONTEXT.
            endif .
      ENDWHILE .

      CLEAR sy-subrc .

  ENDLOOP .

ENDFUNCTION.

Read only

carlos_zhang3
Participant
0 Likes
607

Done by myself !@

Read only

0 Likes
607

Good Work,

if it is possible , Can you send me full code ? I want to try in my system.

what is the content of ZTMPLSTRU ?

cagatayersoylu@gmail

Thanks.