?
Solved

How to specify the FROM Attribute when using SQL DB Mail

Posted on 2011-02-14
4
Medium Priority
?
232 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
In this video we show how to create an Address List 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 Organization >> Ad…
In this video we show how to create a mailbox database 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 Servers >> Data…
Suggested Courses

771 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