1. You can schedule a job at 05:00 AM every day to accompish this, just open Enterprise Manager, explorer MySQLInstance->'Management'->'SQL Server Agent'->right click 'Jobs'->'New Job', then go to 'Steps' pannel to new a step. Choose 'T-SQL' as step type, and copy your T-SQL script used for sending email to the 'Command' field (as you'll schedule the script to run once a day, let's remove the 'WHILE(1=1)' loop). Then go to 'Schedules' pannel to schedule your job step. You can press F1 for detailed help. Sorry I wrote a wrong script in my previous post, for the case that there may be more than 2 persons have same birhday:
declare @email varchar(100), @name varchar(100)
select email,name into #tbl
from tbl_Birthday
where month(birthdate)=month(getdate())
and day(birthdate)=day(getdate())
select @eamil=email,@name='Happy Birthday'+name+'!' from #tbl
WHILE (@email is not null)
BEGIN
EXEC master.dbo.xp_sendmail
@recipients = @email,
@subject = N'Happy Birthday!',
@message = @name,
@attachments='c:\happyBirth.html'--you have use attachment if you want HTML feature
DELETE FROM #tbl where email=@email
select @eamil=email,@name='Happy Birthday'+name+'!' from #tbl
END
DROP TABLE #tbl
------------------------------------
Suggested site:
http://www.howtogeek.com/howto/database/sending-automated-job-email-notifications-in-sql-server-with-smtp/
No comments:
Post a Comment