[dba-SQLServer]Auto email users from SS7 on the 1st of month.

Djabarov, Robert Robert.Djabarov at usaa.com
Thu Jul 10 16:31:16 CDT 2003


You can use CDO object model to avoid having to have SQLMail running on your server.  Also, here's a stored procedure that you can use as a sample.

create procedure dbo.sp_send_cdosysmail (
   @SMTPServer varchar(128),
   @From varchar(100),
   @To varchar(100),
   @Subject varchar(100)= ' ',
   @Body varchar(8000) = ' '
as
   declare @iMsg int                ,
           @hr int                  ,
           @source varchar(255)     ,
           @description varchar(500),
           @output varchar(1000)

-- Do some error handling after each step if you need to.

   exec @hr = sp_OACreate 'CDO.Message', @iMsg out

   exec @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'

   exec @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', @SMTPServer

   exec @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null

   exec @hr = sp_OASetProperty @iMsg, 'To', @To
   exec @hr = sp_OASetProperty @iMsg, 'From', @From
   exec @hr = sp_OASetProperty @iMsg, 'Subject', cast(@Subject as varchar(100))

   exec @hr = sp_OASetProperty @iMsg, 'TextBody', @Body
   exec @hr = sp_OAMethod @iMsg, 'Send', NULL

   if @hr <> 0 begin
      exec @hr = sp_OAGetErrorInfo null, @source out, @description out
      if @hr = 0 begin
         select @output = '  Source: ' + @source
         print  @output
         select @output = '  Description: ' + @description
         print  @output
      end else begin
         print '  sp_OAGetErrorInfo failed.'
         return
      end
   end

   exec @hr = sp_OADestroy @iMsg

GO

Robert Djabarov
Senior SQL Server DBA
USAA IT/DBMS
? (210) 913-3148 - phone
? (210) 753-3148 - pager


 -----Original Message-----
From: 	Joe Rojas [mailto:JRojas at tnco-inc.com] 
Sent:	Thursday, July 10, 2003 1:20 PM
To:	'dba-sqlserver at databaseadvisors.com'
Subject:	[dba-SQLServer]Auto email users from SS7 on the 1st of month.

Hi All,

I have a database in SQL Server 7 that stores time sheet information. Users
submit time sheets for the previous month. For example, on July 1st they
will need to submit their time sheet for June.

I have a table with the users and their e-mail addresses. What I would like
SQL Server to do is on July 1st automatically send out an e-mail to the
users who have not submitted a time sheet that will remind them that it is
due. I do not have a problem with creating a query that will tell me who
these users are, but I would like some help on how to make SQL Server run
this task, on its own, every month and e-mail a reminder to the qualifying
users.

Any ideas?

Thanks!

Joe R.



This electronic transmission is strictly confidential to TNCO, Inc. and
intended solely for the addressee. It may contain information which is
covered by legal, professional, or other privileges. If you are not the
intended addressee, or someone authorized by the intended addressee to
receive transmissions on behalf of the addressee, you must not retain,
disclose in any form, copy, or take any action in reliance on this
transmission. If you have received this transmission in error, please notify
the sender as soon as possible and destroy this message. While TNCO, Inc.
uses virus protection, the recipient should check this email and any
attachments for the presence of viruses. TNCO, Inc. accepts no liability for
any damage caused by any virus transmitted by this email.
_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com





More information about the dba-SQLServer mailing list