I would like to send emails from SQL Server 2008.
Here is my code:
USE mydatabase
declare @keywords nvarchar(3000)
Select @keywords = null
SELECT
@Keywords = Coalesce(@Keywords + '; ', '') + Email
from
SharedDataUser
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'MyTestProfile',
@recipients=@keywords,
@subject = 'Test mail'
I am able to send email by database mail.
Issue
I am sending mail to multiple users. Each user has different due date and I need to send that due date with email body. I didn't find the way. Can anyone help me?
Thanks in advance
You won't be able to have a different body for each recipient using this approach. You could use a cursor to iterate over the recipients, calling sp_send_dbmail for each recipient. You can then set the @body parameter to whatever is appropriate for that recipient i.e. their due date.