?
Solved

How to specify the FROM Attribute when using SQL DB Mail

Posted on 2011-02-14
4
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
Daniel Reynolds earned 2000 total points
ID: 34890479
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
ID: 34890572
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:Daniel Reynolds
Daniel Reynolds earned 2000 total points
ID: 34890648
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
ID: 34890737
Simplest method is setup another dbmail profile using the FROM address you want.  
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

649 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