Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 xp_smtp_sendmail

Author  Topic 

Steve2106
Posting Yak Master

183 Posts

Posted - 2009-02-21 : 11:27:52
Hi Guys,
I have managed to send a timed email using xp_smtp_sendmail & a stored procedure. I now need to make it more useful.
Is there a way, in the same stored procedure, that I can select some records, based on some criteria, loop through the returned records & send an email for each record? An email will be returned in the select statement.

I appreciate the help.

Best Regards,


Steve Wilson.

Steve

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-22 : 01:39:14
you can do that. only think is you need to use loop to loop through the result records, then call xp_smtp_sendmail for each record values in the loop.
Go to Top of Page

Steve2106
Posting Yak Master

183 Posts

Posted - 2009-02-23 : 03:06:16
Hi visakh16,
Thanks for the reply.

Is there any chance you have an example.

Appreciate your help.

Best Regards,

Steve.

Steve
Go to Top of Page

alan.winton@yahoo.com
Starting Member

2 Posts

Posted - 2009-03-03 : 05:21:40
Hi Steve,

I'm using a similar thing to send out reminder emails for events and use a cursor in a SP to loop through a recordset and send an email to each recipient. The basic structure of the cursor is

DECLARE MyCursor CURSOR
FOR
SELECT < SQL statement to select your recordset >

Open MyCursor
begin

FETCH MyCursor INTO < fill variables with first record >
WHILE @@Fetch_Status = 0
begin

exec master..xp_smtp_sendmail

< send email to the recipient >

FETCH MyCursor INTO < fill variables with next record >
end
CLOSE MyCursor
end
DEALLOCATE MyCursor

I hope this helps but let me know if this isn't clear.

Regards,

Alan
Go to Top of Page
   

- Advertisement -