Solved

How to specify the FROM Attribute when using SQL DB Mail

Posted on 2011-02-14
4
224 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
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:xDJR1875
xDJR1875 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Read this checklist to learn more about the 15 things you should never include in an email signature.
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…
how to add IIS SMTP to handle application/Scanner relays into office 365.

910 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

22 Experts available now in Live!

Get 1:1 Help Now