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 2005 Forums
 Other SQL Server Topics (2005)
 Database mail and sender name and email address

Author  Topic 

Kosmo114
Starting Member

1 Post

Posted - 2009-09-24 : 05:33:13
Is there a way in database mail to use a single profile, but declare the email senders address in the proceedure that fetches the email message from my table. I have an email relay I use to send outbound emails from multiple domains, and I house the from name, and from email in my email table. I want to avoid setting up multiple email profiles in sql server 2005.
Below is my proceedure fetching emails prior to sending. I was hoping someone might have done something similar and can offer a sugestion.

DECLARE @ID as INT
DECLARE @Mailto as varchar(5000)
DECLARE @Subject as varchar(5000)
DECLARE @Body as varchar(8000)
DECLARE @CC as varchar(5000)
DECLARE @Bcc as varchar(5000)

DECLARE EmailCursor CURSOR FOR
SELECT ID, Mailto, Subject, Body, CC, Bcc FROM MailingList
WHERE status is NULL or status = 0

OPEN EmailCursor

FETCH NEXT FROM EmailCursor INTO @ID, @Mailto, @Subject, @Body, @CC, @Bcc
WHILE @@FETCH_STATUS = 0 and @@Error = 0
BEGIN
exec msdb..sp_send_dbmail
@profile_name = 'Outboundemail',
@recipients = @Mailto,
@copy_recipients = @CC,
@blind_copy_recipients = @Bcc,
@subject = @Subject,
@body = @Body
   

- Advertisement -