/*
This piece of code use xp_smtp_sendmail untility.
It suppose to lookup email addresses in the email table, send the email to the people still havn't send their timecard yet. However It only send the email to the last person in the table. I wonder where it is wrong?
大侠们,快出手啊*/
Use IT
declare
@TO NVARCHAR(4000),
@rc INT
Declare MyCursor Cursor For
Select email_addr+',' From email Where Stat = 'O'
Open MyCursor
Fetch Next From MyCursor Into @TO
While @@Fetch_Status = 0
BEGIN
Print @To
Fetch Next From MyCursor Into @To
exec @rc = master.dbo.xp_smtp_sendmail
@FROM = N'timecard_admin@aed.org',
@to = @TO,
@FROM_NAME = N'Timecard_Admin',
@priority = N'NORMAL',
@subject = N'This is just a testing email.',
@message = N'Your timesheet is overdue, please send it ASAP.',
@type = N'text/plain',
@server = N'mail.aed.org'
select RC = @rc
End
Close MyCursor
Deallocate MyCursor