Solved

How to specify the FROM Attribute when using SQL DB Mail

Posted on 2011-02-14
4
227 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:
Daniel Reynolds earned 500 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 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

770 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