Send Mail as attachments


FUNCTION zsd_reset_password.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IM_BNAME) TYPE  RSYST-BNAME OPTIONAL
*"  EXPORTING
*"     VALUE(MESSAGE) TYPE  STRING
*"----------------------------------------------------------------------
  
DATA:        gt_table TYPE STANDARD TABLE OF zsd_user_login,
               gs_table 
TYPE                   zsd_user_login.
 
DATA:  password   TYPE  sld_password,
        password1  
TYPE  sld_password,
        pwdbase64  
TYPE  sld_b64pwd,
        pwdbase641 
TYPE  sld_b64pwd.
*Data Declaration
*----------------
  
DATAit_contents   TYPE STANDARD TABLE OF soli,
        wa_contents    
TYPE soli,
        it_attachment 
TYPE solix_tab,
        wa_receivers  
TYPE uiys_iusr,
        ld_subject    
TYPE so_obj_des,
        ld_att_size   
TYPE so_obj_len,
        ld_att_text   
TYPE xstring,
        ld_att_type   
TYPE so_obj_tp VALUE 'TXT',
        ld_att_sub    
TYPE so_obj_des VALUE 'Attachment'.

  
DATAsend_email   TYPE REF TO cl_bcs,
        send_request 
TYPE REF TO cl_send_request_bcs,
        document     
TYPE REF TO cl_document_bcs,
        recipient    
TYPE REF TO if_recipient_bcs.

  
DATA:  p_subjct TYPE string VALUE 'New Password',
        p_bodtxt 
TYPE string"  VALUE 'Dear User Find your password in attchments',
        p_atttxt 
TYPE string"
        p_recip  
TYPE string"

  
SELECT FROM zsd_user_login INTO TABLE gt_table  WHERE user_id im_bname.
  
IF sy-subrc EQ 0.
    
READ TABLE gt_table INTO gs_table INDEX 1.

    
if gs_table-email IS NOT INITIAL and gs_table-bcode is NOT INITIAL.

    
move gs_table-bcode to pwdbase641.
    
move pwdbase641      to pwdbase64.

    
CALL FUNCTION 'DECODE_SLDPWD_BASE64'
      
EXPORTING
        pwdbase64       
pwdbase64
     
IMPORTING
       PASSWORD        
password
              
.
    
CONCATENATE 'Reset Password is' password INTO p_bodtxt.

    p_recip 
gs_table-email.
    p_atttxt 
password.


    ld_subject 
p_subjct.

    
CONCATENATE '<html><body><p>' p_bodtxt '</p></body></html>'
                     
INTO wa_contents-line.
    
APPEND wa_contents TO it_contents.

* Create instance of the email class
    send_email 
cl_bcs=>create_persistent( ).

* Create email document inc type, subject and boby text
    document 
cl_document_bcs=>create_document(
                  i_type    
'HTM'
                  i_subject 
ld_subject
                  i_text    
it_contents ).

* Convert attachment text to xstring
    
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      
EXPORTING
        
text   p_atttxt
*       MIMETYPE       = ' '
*       ENCODING       =
      
IMPORTING
        
buffer ld_att_text
      
EXCEPTIONS
        failed 
1
        
OTHERS 2.

* Add converted attachment text to the email attachment table
    it_attachment 
cl_document_bcs=>xstring_to_solixld_att_text ).

* Calculate size of attachment
    ld_att_size   
xstrlenld_att_text ).

* Add the attachment table to the document
    
CALL METHOD document->add_attachment(
        i_attachment_type    
ld_att_type
        i_attachment_subject 
ld_att_sub
        i_attachment_size    
ld_att_size
        i_att_content_hex    
it_attachment ).

* Assign document and all its details to the email
    
CALL METHOD send_email->set_documentdocument ).

* Setup email recipient
    wa_receivers
-email p_recip.
    recipient 
cl_cam_address_bcs=>create_internet_addresswa_receivers-email ).

*Assign recipient to email
    
CALL METHOD send_email->add_recipient
      
EXPORTING
        i_recipient 
recipient
        i_express   
'X'.

*Send email
    
CALL METHOD send_email->sendi_with_error_screen 'X' ).

* Commit work!!! This is important email will not get sent or appear in SOST without this
    
COMMIT WORK.

  
ENDIF.
  
ENDIF.

  
if sy-subrc eq 0.
    
MESSAGE 'Password sent sucuess'.
    
else.
     
MESSAGE 'Error to sending password check with admin'.
   
endif.
ENDFUNCTION.

Comments

Popular posts from this blog

Business senario : FB60 AND FB70 validation and subsituation

MB_MIGO_BADI THIS BADI USED TO POSTING DATA IN MIGO

all user exit mv45afzz (implicit user exit )