Solved

How to specify the FROM Attribute when using SQL DB Mail

Posted on 2011-02-14
4
222 Views
Last Modified: 2012-05-11
We insert records into a table from our website, and then use the sql db send mail to actually email the information out to it's recipients. We do this for tracking purposes.

Is it possible to specify the FROM attribute when sending the email to be an address OTHER than the email address specified in the SQL DB Send Email Profile?

If so, how can that be done? [we have created a field in the email table to hold the FROM email address]

BEGIN
    SELECT   
		@EmailQueueID=EmailQueueID,
		@EmailID=EmailID,
		@AppID=AppID, 
		@MessageTypeID = MessageTypeID,
		@EmailTo=EmailTo, 
		@EmailFrom=EmailFrom,
		@EmailSubject=EmailSubject,
		@EmailCC=EmailCC,
		@EmailBCC=EmailBCC,
		@EmailAttachment=EmailAttachment,
		@EmailBody=EmailBody,
		@CreateDate=CreateDate,
		@SendDate=SendDate  
    FROM 
		#tmpEmailQueue
	WHERE
		EmailQueueID = @CurrentRow

    --------------------------------------------------------------------------------
    ---- http://msdn.microsoft.com/en-us/library/ms190307(SQL.90).aspx
    ---- Call SQL DB Mail in MSDB Database using values of rows in email queue
    --------------------------------------------------------------------------------
    EXEC @ReturnCode = msdb..sp_send_dbmail
         @profile_name = @EmailProfileName,
         @recipients = @EmailTo,
         @copy_recipients = @EmailCC,
         @blind_copy_recipients = @EmailBCC,
         @body = @EmailBody,
		 @body_format = 'HTML',
         @subject = @EmailSubject;

Open in new window

0
Comment
Question by:jsvb1977
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
xDJR1875 earned 500 total points
Comment Utility
When you set up dbMail, you set up the account that is the sender. It uses that in the email.
0
 

Author Comment

by:jsvb1977
Comment Utility
xDJR1875:

Understood. Since the table we use has a field for 'FROM' -- [meaning, i can populate that field with any email address i want] I was wondering if it is possible to pass that value through the DB SEND Mail and use that as the FROM email address instead of the email address that is configured in the DB Mail Profile.

Does that make sense?
Or was your reply essentially saying that it is not possible?

Jason
0
 
LVL 17

Assisted Solution

by:xDJR1875
xDJR1875 earned 500 total points
Comment Utility
Not sure if there is another method, but using the stored procedure sp_send_dbmail

The only options/parameters it has are:
sp_send_dbmail [ [ @profile_name = ] 'profile_name' ]
    [ , [ @recipients = ] 'recipients [ ; ...n ]' ]
    [ , [ @copy_recipients = ] 'copy_recipient [ ; ...n ]' ]
    [ , [ @blind_copy_recipients = ] 'blind_copy_recipient [ ; ...n ]' ]
    [ , [ @subject = ] 'subject' ]
    [ , [ @body = ] 'body' ]
    [ , [ @body_format = ] 'body_format' ]
    [ , [ @importance = ] 'importance' ]
    [ , [ @sensitivity = ] 'sensitivity' ]
    [ , [ @file_attachments = ] 'attachment [ ; ...n ]' ]
    [ , [ @query = ] 'query' ]
    [ , [ @execute_query_database = ] 'execute_query_database' ]
    [ , [ @attach_query_result_as_file = ] attach_query_result_as_file ]
    [ , [ @query_attachment_filename = ] query_attachment_filename ]
    [ , [ @query_result_header = ] query_result_header ]
    [ , [ @query_result_width = ] query_result_width ]
    [ , [ @query_result_separator = ] 'query_result_separator' ]
    [ , [ @exclude_query_output = ] exclude_query_output ]
    [ , [ @append_query_error = ] append_query_error ]
    [ , [ @query_no_truncate = ] query_no_truncate ]
    [ , [ @mailitem_id = ] mailitem_id ] [ OUTPUT ]
 
0
 
LVL 5

Expert Comment

by:robertg34
Comment Utility
Simplest method is setup another dbmail profile using the FROM address you want.  
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now