12-30-2005 2:35 PM
Hi!
I've to create buttons on a dynpro, which process the currently installed frontend mail client (zB. Notes, Outlook, etc.) and fill the recipients, subject and mail body dynamically at the end of "PROCESS AFTER INPUT".
The application handling should be like a HTML-Link (for example: <a href="mailto:beispiel@example.org?body=Hello%20Fritz,%0D%0A%0D%0Aich%20wollte%20nur%20sagen,%20dass%20">Mail mit Body</a>).
The solution should work in SAPGui for Windows and SAPGui for HTML.
Does anybody knows a example coding?
Any hints are welcome.
Thanks, happy new year!
Peter Lintner
12-31-2005 6:31 AM
develop a FM with the following code and call it onclick of a button.
function y_outlook_mail_create.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_SUBJECT) OPTIONAL
*" TABLES
*" EMAIL_BODY STRUCTURE SOLI OPTIONAL
*" ADDRESS_LIST STRUCTURE SOLI OPTIONAL
*" ATTACHMENTS STRUCTURE SOLI OPTIONAL
*" EXCEPTIONS
*" INVALID_PATH
*" DOWNLOAD_FAILED
*" EXECUTION_FAILED
*"----------------------------------------------------------------------
data:
v_translate(2),
it_vbs like soli
occurs 50 with header line,
v_last,
v_vbs_filename like rlgrap-filename,
wf_filename like rlgrap-filename ,
commandline(1000).
*- Prepare a code to translate a quote into a hex-tab
*- so it can then be translated back to 2 double quotes.
concatenate '"' '9' into v_translate.
* CON_HEX-TAB'
append:
'Dim myolapp ' to it_vbs,
'Dim olNamespace ' to it_vbs,
'Dim myItem ' to it_vbs,
'Dim myRecipient ' to it_vbs,
'Dim myAttachments ' to it_vbs,
' ' to it_vbs,
'Set myolapp = CreateObject("Outlook.Application") ' to it_vbs,
'Set olNamespace = myolapp.GetNamespace("MAPI") ' to it_vbs,
'Set myItem = myolapp.CreateItem(olMailItem) ' to it_vbs,
' ' to it_vbs.
*- Translate the body into a single line.
loop at address_list.
concatenate
'Set myRecipient = myItem.Recipients.Add("'
address_list
'")'
into it_vbs.
append it_vbs.
endloop.
append:
'myItem.VotingOptions = "Approve;Reject"' to it_vbs.
*- Build the subject line.
concatenate
'myItem.Subject = "'
i_subject
'"'
into it_vbs.
append it_vbs.
*- Prepare attachments
append:
'Set myAttachments = myItem.Attachments' to it_vbs.
*- Check if the attachment exists
loop at attachments.
clear wf_filename .
move: attachments-line to wf_filename .
call function 'WS_QUERY'
exporting
filename = wf_filename "ATTACHMENTS
query = 'FE'
exceptions
inv_query = 1
no_batch = 2
frontend_error = 3
others = 4.
if sy-subrc eq 0.
concatenate 'myAttachments.Add("'
attachments
'")'
into it_vbs.
append it_vbs.
* ' olByValue, 1, "4th Quarter 1996 Results Chart"'
* append ' olByReference, 1' to it_vbs.
else.
message i017(zz) with
'Could not attach' attachments.
endif.
endloop.
*- Prepare the email body.
clear: v_last, it_vbs.
append it_vbs.
loop at email_body.
at first.
append 'myitem.HTMLbody = _' to it_vbs.
endat.
at last.
v_last = 'X'.
endat.
translate email_body using v_translate.
while sy-subrc eq 0.
replace '09' with '""' into email_body.
endwhile.
if v_last = 'X'.
concatenate '"' email_body '" &vbCrLf '
into it_vbs.
else.
concatenate '"' email_body '" &vbCrLf &_'
into it_vbs.
endif.
append it_vbs.
endloop.
append 'myItem.Display' to it_vbs.
*- Prepare the vbscript filename for download and execution
clear v_vbs_filename.
call function 'WS_QUERY'
exporting
environment = 'TEMP'
query = 'EN'
importing
return = v_vbs_filename
exceptions
inv_query = 1
no_batch = 2
frontend_error = 3
others = 4.
if sy-subrc <> 0.
raise invalid_path.
endif.
concatenate v_vbs_filename 'mail.vbs'
into v_vbs_filename.
commandline = v_vbs_filename.
*- Download the file
call function 'WS_DOWNLOAD'
exporting
filename = v_vbs_filename
filetype = 'DAT'
mode = 'S'
tables
data_tab = it_vbs
exceptions
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
others = 8.
if sy-subrc <> 0.
raise download_failed.
endif.
call function 'WS_EXECUTE'
exporting
commandline = commandline
program = 'WSCRIPT.EXE'
exceptions
frontend_error = 1
no_batch = 2
prog_not_found = 3
illegal_option = 4
others = 5.
if sy-subrc <> 0.
raise execution_failed.
endif.
endfunction.
Regards
Raja
12-31-2005 6:31 AM
develop a FM with the following code and call it onclick of a button.
function y_outlook_mail_create.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_SUBJECT) OPTIONAL
*" TABLES
*" EMAIL_BODY STRUCTURE SOLI OPTIONAL
*" ADDRESS_LIST STRUCTURE SOLI OPTIONAL
*" ATTACHMENTS STRUCTURE SOLI OPTIONAL
*" EXCEPTIONS
*" INVALID_PATH
*" DOWNLOAD_FAILED
*" EXECUTION_FAILED
*"----------------------------------------------------------------------
data:
v_translate(2),
it_vbs like soli
occurs 50 with header line,
v_last,
v_vbs_filename like rlgrap-filename,
wf_filename like rlgrap-filename ,
commandline(1000).
*- Prepare a code to translate a quote into a hex-tab
*- so it can then be translated back to 2 double quotes.
concatenate '"' '9' into v_translate.
* CON_HEX-TAB'
append:
'Dim myolapp ' to it_vbs,
'Dim olNamespace ' to it_vbs,
'Dim myItem ' to it_vbs,
'Dim myRecipient ' to it_vbs,
'Dim myAttachments ' to it_vbs,
' ' to it_vbs,
'Set myolapp = CreateObject("Outlook.Application") ' to it_vbs,
'Set olNamespace = myolapp.GetNamespace("MAPI") ' to it_vbs,
'Set myItem = myolapp.CreateItem(olMailItem) ' to it_vbs,
' ' to it_vbs.
*- Translate the body into a single line.
loop at address_list.
concatenate
'Set myRecipient = myItem.Recipients.Add("'
address_list
'")'
into it_vbs.
append it_vbs.
endloop.
append:
'myItem.VotingOptions = "Approve;Reject"' to it_vbs.
*- Build the subject line.
concatenate
'myItem.Subject = "'
i_subject
'"'
into it_vbs.
append it_vbs.
*- Prepare attachments
append:
'Set myAttachments = myItem.Attachments' to it_vbs.
*- Check if the attachment exists
loop at attachments.
clear wf_filename .
move: attachments-line to wf_filename .
call function 'WS_QUERY'
exporting
filename = wf_filename "ATTACHMENTS
query = 'FE'
exceptions
inv_query = 1
no_batch = 2
frontend_error = 3
others = 4.
if sy-subrc eq 0.
concatenate 'myAttachments.Add("'
attachments
'")'
into it_vbs.
append it_vbs.
* ' olByValue, 1, "4th Quarter 1996 Results Chart"'
* append ' olByReference, 1' to it_vbs.
else.
message i017(zz) with
'Could not attach' attachments.
endif.
endloop.
*- Prepare the email body.
clear: v_last, it_vbs.
append it_vbs.
loop at email_body.
at first.
append 'myitem.HTMLbody = _' to it_vbs.
endat.
at last.
v_last = 'X'.
endat.
translate email_body using v_translate.
while sy-subrc eq 0.
replace '09' with '""' into email_body.
endwhile.
if v_last = 'X'.
concatenate '"' email_body '" &vbCrLf '
into it_vbs.
else.
concatenate '"' email_body '" &vbCrLf &_'
into it_vbs.
endif.
append it_vbs.
endloop.
append 'myItem.Display' to it_vbs.
*- Prepare the vbscript filename for download and execution
clear v_vbs_filename.
call function 'WS_QUERY'
exporting
environment = 'TEMP'
query = 'EN'
importing
return = v_vbs_filename
exceptions
inv_query = 1
no_batch = 2
frontend_error = 3
others = 4.
if sy-subrc <> 0.
raise invalid_path.
endif.
concatenate v_vbs_filename 'mail.vbs'
into v_vbs_filename.
commandline = v_vbs_filename.
*- Download the file
call function 'WS_DOWNLOAD'
exporting
filename = v_vbs_filename
filetype = 'DAT'
mode = 'S'
tables
data_tab = it_vbs
exceptions
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
others = 8.
if sy-subrc <> 0.
raise download_failed.
endif.
call function 'WS_EXECUTE'
exporting
commandline = commandline
program = 'WSCRIPT.EXE'
exceptions
frontend_error = 1
no_batch = 2
prog_not_found = 3
illegal_option = 4
others = 5.
if sy-subrc <> 0.
raise execution_failed.
endif.
endfunction.
Regards
Raja
12-31-2005 10:03 AM
to open a browser you can just use FM CALL_BROWSER
Regards
Raja
12-31-2005 11:54 AM
Hi,
Another option to open a browser is
call method cl_gui_frontend_services=>execute
exporting
document = 'http://www.sap.com'
exceptions
others = 1.
Regards,
Suresh Datti