How can I customize my own email header when using sp_send_dbmail with MS SQL Server?

I am currently using T-SQL to send email with an attachment from a stored procedure:

EXEC @return_status = msdb.dbo.sp_send_dbmail
    @profile_name = 'ProfileName',
    @recipients = @recipients,
    @body = @mailbody,
    @subject = @subject,
    @file_attachments = @full_attachment_filename

      

I would like to set a custom header in the email being sent. Is there a way to do this with a stored procedure sp_send_dbmail

?

Additional information: SQL Server version is 2005, and E-mail sending via Microsoft Exchange Server (2003).

+3


source to share


2 answers


By default, sp_send_dbmail does not have the ability to edit header information as per your question ...

I know this because I see the input parameters and the code definition:



USE [msdb]
EXEC sp_help sp_send_dbmail

      

However, you can edit the profile so that replies (automatically or otherwise) go to an email address like donotreply@youremailaddress.co.uk , or leave it blank?

+1


source


Answer: no, gsc_dba's answer is correct, but I would like to go a little deeper. I looked at the code that composes sp_send_dbmail into the table it writes to, msdb.dbo.sysmail_mailitems has no fields to place custom headers or any field that remotely matches the invoice, so even if you bypass the system stored procedure and write to the table directly there is no way yet to make the database mailbox handle it.



0


source







All Articles