260 likes | 379 Views
INT415: Sending E-Mail from within ASE Stored Procedures. Steve Bradley Sr. Database Administrator Nielsen Media Research August 15-19, 2004. Who I am. Sr. Database Administrator Information Technology Professional since 1978 Employment History Nielsen Media Research The Capital Group
E N D
INT415: Sending E-Mail from within ASE Stored Procedures Steve Bradley Sr. Database Administrator Nielsen Media Research August 15-19, 2004
Who I am. • Sr. Database Administrator • Information Technology Professional since 1978 • Employment History • Nielsen Media Research • The Capital Group • Software AG • Weyerhaeuser • Bigelow-Sanford
E-Mail History • 1st Internet use of communication between computers? • 1st programmer to develop a program to send electronic messages? • 1st use of satellites for transferring data packets?
Objective • To identify ways that Sybase applications written on a UNIX platform can send E-Mails
Command xp_sendmail Windows NT only - Sends a message to the specified recipients. The message is either text or the results of a Transact-SQL query.
Command xp_sendmail recipient [; recipient] . . . [, subject] [, cc_recipient] [, bcc_recipient] . [, {query | message}] [, attachname] [, attach_result = {true | false}] [, echo_error = {true | false}] [, include_file [, include_file] . . .] [, no_column_header = {true | false}] [, no_output = {true | false}] [, width] [, separator] [, dbuser] [, dbname] [, type] [, include_query = {true | false}]
Command Sequence • xp_startmail • xp_sendmail • xp_stopmail
Problem Statement Since the xp_sendmail feature of Sybase ASE on UNIX is not operational, how can E-Mails be sent from an application written on this platform?
Goal To identify methods that can be used to simulate the active use of the xp_sendmail function.
Methods • Issuing a UNIX mail command via xp_cmdshell • Calling a Stored Procedure that calls xp_cmdshell to issue the UNIX mail command • Calling a Stored Procedure that issues xp_sendmail on a ASA Server running on NT • Remotely executing xp_sendmail on ASA on NT machine
Method 1: Issuing a UNIX mail command via xp_cmdshell declare @mail_string varchar(255) Select @subject = '/var/tmp/errormsg_01‘ , @recipient = 'Steve.Bradley@NielsenMedia.com‘ select @mail_string = '/usr/bin/mailx -s "D2DDM" ' + @recipient + ' < "' + @subject + '"' print @mail_string exec xp_cmdshell @mail_string
Method 1: Issuing a UNIX mail command via xp_cmdshell • Pros • Simplistic • Cons • Least security • Minimal message
Method 2: Calling a Stored Procedure that calls xp_cmdshell to issue the UNIX mail command
Method 2: Calling a Stored Procedure that calls xp_cmdshell to issue the UNIX mail command createproc sp_sendmail (@recipient varchar(255) = NULL, @subject varchar(255) = NULL ) as declare @mail_string varchar(255) Select @subject = '/var/tmp/errormsg_01‘ , @recipient = 'Steve.Bradley@NielsenMedia.com‘ select @mail_string = '/usr/bin/mailx -s "D2DDM" ' + @recipient + ' < "' + @subject + '"' print @mail_string exec xp_cmdshell @mail_string return
Method 2: Calling a Stored Procedure that calls xp_cmdshell to issue the UNIX mail command • Pros • Security can be provided via execute authority • Variables can be used to pass message, address, and subject information • Use of distribution lists • Cons • Called stored procedure would need to be in another database with limited access
Method 3: Calling a Stored Procedure that issues xp_sendmail on a ASA Server running on NT
Method 3: Calling a Stored Procedure that issues xp_sendmail on a ASA Server running on NT • Pros • Security can be provided via remote server • Variables can be used to pass message, address, and subject information • Use of distribution lists • Cons • Called stored procedure would need to be maintained in sybsystemprocs
Method 4: Remotely executing xp_sendmail on ASA on NT machine
Method 4: Remotely executing xp_sendmail on ASA on NT machine • Pros • Security can be provided via remote server login that has limited authorization • Variables can be used to pass message, address, and subject information • Use of distribution lists • Cons • User/applications must have ability to make calls to remote server • Limited security
Comparison of Methods • Issuing a UNIX mail command via xp_cmdshell • Calling a Stored Procedure that calls xp_cmdshell to issue the UNIX mail command • Calling a Stored Procedure that issues xp_sendmail on a ASE Server running on NT • Remotely executing xp_sendmail on SQL Anywhere on NT machine
Bottom Line • Security • Costs • Environment
Business Cases • Database Administration Event Notification • Client Event Notification • Application Event Notification
Expand to Web Services Create a Web Service that can be utilized to handle E-Mail processing that is callable from within ASE.
Real-Time vs. Right Time E-Mail • Real-Time implies that E-Mail should be sentat the time of the event • Right-Time means that the appropriate time for sending the E-Mail must be determined by the event