We require the ability to sent emails from stored procedures (SQL Server 2012) via SMTP.

We need to retain control over the emails "FROM" address and "Display Name" so this I believe rules out Database Mail as these are hard set in the created profiles (would be great to over ride tho! Anyone know how?)

What other options are available to us?

Thanks Paul

UPDATE: Would it be stupid to, in code, create the required temporary Database Mail profile, use it to send the required email once, and then delete the profile?

有帮助吗?

解决方案

From 2008 onwards you can create a basic profile and then override the details with @from_address/reply_to;

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'my profile',
    ...
    @subject = 'The Spice must flow',
    @from_address = '"Bob Smith" <xxx@yyy.com>',
    @reply_to = 'xxx@yyy.com'

其他提示

Here's one option. Create an SSIS package.

Allow your stored procedure to queue up email information into a database table. Your SSIS package would query this table and send an email based on the table values for each row in the table and delete each record (or flag it as processed so you retain a record of the emails that were sent) after the email is sent. Then schedule a SQL job that runs your package for whatever interval works best for your requirements.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top