‎2008 Jul 17 1:26 PM
Hi everybody....
I have a program which sends mail to the user if the program succesfully completed. The output result goes to user as email.
This program will be executed by many person. In my program I am passing the receivers email id. whoever will execute that program the mail will go from his or her id. Now I need to change the sender's id. for any user the sender id will be same. Is it possible to change the sender's id?? please help me.... If there is any function module to send mail by changing the sender's user id.
‎2008 Jul 17 1:30 PM
Hi,
I think by default you would have given receiver's email id. Instead you can give sender's mail id either by hard coding or from a table of email addresses. Or if you could give your code, I can help you.
‎2008 Jul 17 1:31 PM
SG,
PARAMETERS:p_addr type AD_SMTPADR.
INITIALIZATION.
CALL FUNCTION 'FTR_CORR_CHECK_EMAIL_SAP_USER'
EXPORTING
I_USER = SY-UNAME
IMPORTING
E_EMAIL_ADDRESS = p_addr
EXCEPTIONS
MAIL_ADDRESS = 1
DETERMINATION_ERROR = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.Amit.
‎2008 Jul 17 1:36 PM
Amit I think the function module u have given returns the id of the given sy-uname. But my problem is different. I need to give the same id for different users. for example.... if the sy-uname is A or B or C then for all those users sender's id will be XYZ. Now tell me is it possible???? Plz reply....
‎2008 Jul 17 1:37 PM
Hi
Please check it..Use the FM SO_DOCUMENT_SEND_API1.
Give the sender address in c_sender.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = l_doc_chng
put_in_outbox = c_check
sender_address = c_sender
sender_address_type = 'INT'
commit_work = space
tables
packing_list = i_packlist
contents_txt = i_content
receivers = i_receivers
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.
Edited by: Subhankar Garani on Jul 17, 2008 2:38 PM
‎2008 Jul 17 1:43 PM
Hi,
This program is used to send mail's to the email id's we give in the selection screen. Please gothrough the code. The requirement may differ. But use the same logic for the email's to be sent.
REPORT ztest.
declaration of Tables
TABLES: adr6, epsf.
type declaration
TYPES: BEGIN OF ty_sdbah,
beg TYPE sdba_begin,
funct TYPE sdba_funct,
sysid TYPE sdba_sysid,
ende TYPE sdba_end,
END OF ty_sdbah.
declaration of internal tables & workareas
DATA: it_sdbah TYPE TABLE OF ty_sdbah,
wa_sdbah TYPE ty_sdbah,
lt_dir_list TYPE TABLE OF epsfili,
wa_dir_list TYPE epsfili,
lt_solitab TYPE soli_tab,
wa_solitab LIKE LINE OF lt_solitab,
wa_atttachment TYPE solix.
declaration of global variables
DATA: gv_file LIKE rlgrap-filename,
gv_line TYPE string,
gv_line_temp TYPE string,
gv_lst TYPE string,
gv_dirname TYPE epsf-epsdirnam,
gv_name(40) TYPE c,
gv_doctype TYPE so_obj_tp,
attachment TYPE solix_tab,
state TYPE string VALUE 'State:',
gv_state TYPE string,
gv_state1 TYPE string.
declaration of global constants
CONSTANTS: gc_aliass TYPE dirname VALUE 'DIR_DBAHISTORY',
gc_beg TYPE char03 VALUE 'dba'.
DATA : bcs_exception TYPE REF TO cx_bcs,
send_request TYPE REF TO cl_bcs.
DATA: l_subject TYPE so_obj_des,
l_mail_text TYPE bcsy_text,
l_mail_text_row TYPE soli.
Declaring local variables
DATA: lv_flag TYPE char01,
lv_err_msg TYPE char20,
lv_s_msg TYPE char25.
defining selection screen
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_email FOR adr6-smtp_addr NO INTERVALS OBLIGATORY.
PARAMETERS : p_email TYPE adr6-smtp_addr NO-DISPLAY.
PARAMETERS : p_sub TYPE string.
SELECTION-SCREEN : END OF BLOCK b1.
start of selection event
START-OF-SELECTION.
Using this subroutine to get the dirname and DBA Logs
PERFORM get_data.
using this subroutine to get the latest backup details
PERFORM process_data.
Using this subroutine to read the date from application server
PERFORM read_application_data.
Using this subroutine to send email to given email id's from select-options
PERFORM send_mail.
END-OF-SELECTION.
IF lv_flag = 'X'.
FORMAT COLOR = 6.
WRITE: lv_err_msg .
FORMAT COLOR OFF.
ELSE.
FORMAT COLOR = 5.
LOOP AT lt_dir_list INTO wa_dir_list WHERE name = gv_name.
WRITE : wa_dir_list-name,
wa_dir_list-size.
ENDLOOP.
WRITE: lv_s_msg .
FORMAT COLOR OFF.
LOOP AT l_mail_text INTO l_mail_text_row.
WRITE:/ l_mail_text_row.
ENDLOOP.
ENDIF.
&----
*& Form get_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM get_data .
get dirname from user_dir table
CLEAR: gv_dirname.
SELECT SINGLE dirname INTO gv_dirname
FROM user_dir
WHERE aliass EQ gc_aliass.
If records not found, then raise error message
IF sy-subrc <> 0.
MESSAGE text-002 TYPE 'I'.
ENDIF.
REFRESH: it_sdbah.
get data from SDBAH table
SELECT beg funct sysid ende
INTO TABLE it_sdbah
FROM sdbah
WHERE funct = 'sda' AND obj = 'DATA'
ORDER BY beg DESCENDING.
If records not found, then raise error message
IF sy-subrc <> 0.
MESSAGE text-003 TYPE 'I'.
ELSE.
get the latest backup details
READ TABLE it_sdbah INTO wa_sdbah INDEX 1.
IF sy-subrc = 0.
concatenate to gv_name
CONCATENATE gc_beg wa_sdbah-beg '.' wa_sdbah-funct INTO gv_name.
ENDIF.
ENDIF.
ENDFORM. " get_data
&----
*& Form process_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM process_data .
call function, to get list of backups
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = gv_dirname
TABLES
dir_list = lt_dir_list.
if records not found, then raise error messsage
IF sy-subrc <> 0.
MESSAGE text-004 TYPE 'I'.
ENDIF.
sort the list in descending order
SORT lt_dir_list BY name DESCENDING.
display the latest backup details
LOOP AT lt_dir_list INTO wa_dir_list WHERE name = gv_name.
WRITE : wa_dir_list-name,
wa_dir_list-size.
ENDLOOP.
translate directory name to upper case
TRANSLATE gv_dirname TO UPPER CASE.
CALL FUNCTION '/SAPDII/SPP05_CONVERT_UPPERCAS'
EXPORTING
if_input = gv_dirname
if_langu = sy-langu
IMPORTING
ef_output = gv_dirname.
.
concatenate to get the file path
CONCATENATE gv_dirname '\' wa_dir_list-name INTO gv_file.
ENDFORM. " process_data
&----
*& Form read_application_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM read_application_data .
read the contents of the file
CLEAR: lv_flag.
OPEN DATASET gv_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
DO.
READ DATASET gv_file INTO gv_line.
IF sy-subrc NE 0.
EXIT.
ENDIF.
wa_solitab-line = gv_line.
APPEND wa_solitab TO lt_solitab.
IF gv_line IS NOT INITIAL.
gv_lst = gv_line.
ENDIF.
CLEAR: gv_line.
gv_line_temp = gv_line.
SPLIT gv_line_temp AT state INTO gv_state gv_state1.
CONDENSE gv_state1.
ENDDO.
ELSE.
lv_flag = 'X'.
lv_err_msg = text-005.
STOP.
***
ENDIF.
close the file
CLOSE DATASET gv_file.
ENDFORM. " read_application_data
&----
*& Form send_mail
&----
text
----
--> p1 text
<-- p2 text
----
FORM send_mail .
convert internal table contents to solix tab format
CALL FUNCTION 'SO_SOLITAB_TO_SOLIXTAB'
EXPORTING
ip_solitab = lt_solitab
IMPORTING
ep_solixtab = attachment.
send email to the recipients
TRY.
assigning values to local variable
CONCATENATE p_sub '-' wa_sdbah-beg '-' gv_state1 INTO l_subject.
add the contents from internal table lt_solitab to l_mail_text
LOOP AT lt_solitab INTO wa_solitab.
l_mail_text_row = wa_solitab-line.
APPEND l_mail_text_row TO l_mail_text.
CLEAR: l_mail_text_row,
wa_solitab.
ENDLOOP.
DATA: document TYPE REF TO cl_document_bcs,
num_rows TYPE i,
text_length TYPE so_obj_len.
DESCRIBE TABLE l_mail_text LINES num_rows.
num_rows = num_rows * 255.
MOVE num_rows TO text_length.
call method, to create document
TRY.
CALL METHOD cl_document_bcs=>create_document
EXPORTING
i_type = 'RAW'
i_subject = l_subject
i_length = text_length
i_text = l_mail_text
RECEIVING
result = document.
CATCH cx_document_bcs .
ENDTRY.
LOOP AT s_email.
send_request = cl_bcs=>create_persistent( ).
send_request->set_document( document ).
DATA: sender TYPE REF TO cl_sapuser_bcs.
sender = cl_sapuser_bcs=>create( 'SAPUSER' ).
TRY.
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
CATCH cx_send_req_bcs .
ENDTRY.
DATA: recipient TYPE REF TO if_recipient_bcs.
get email ids from selection screen
p_email = s_email-low.
recipient = cl_cam_address_bcs=>create_internet_address( p_email ).
send_request->add_recipient( EXPORTING i_recipient = recipient ).
send_request->set_send_immediately( 'X' ).
send_request->send( ).
COMMIT WORK.
ENDLOOP.
lv_s_msg = text-006.
WRITE : 'Sent Successfully'.
CATCH cx_bcs INTO bcs_exception.
ENDTRY.
ENDFORM. " send_mail