i486
i486

Reputation: 6564

Send email from SQL Server 2005 / 2008

I have to send emails from SQL Server 2005 or 2008. I have done this in the past with additional stored procedures (sp_send_html_mail) and complex configuration / activations. Is there standard build-in stored procedure which sends email via SMTP (not MAPI/CAPI/Outlook profiles)? I found sp_send_dbmail on this topic but not sure is it the only one and what security issues are possible (except spam)?

Upvotes: 0

Views: 348

Answers (1)

WillG
WillG

Reputation: 874

Yes, sp_send_dbmail is the one to use for both SQL Sever 2005 and 2008.

You will need to make sure it has been configured on your server. It's been a while since I did such a config, but if memory serves me correctly, it is off by default. Have a look at the MS docs for that process, Configure Database Mail. Setting an SMTP server is doable as well. There are lots of options in there so give it a thorough review.

If you are worried about unwanted use of that sp you can use roles and/or execute permission to limit access to it. From the MS docs on troubleshooting dbmail:

To send Database mail, users must be a user in the msdb database and a member of the DatabaseMailUserRole database role in the msdb database. To add msdb users or groups to this role use SQL Server Management Studio or execute the following statement for the user or role that needs to send Database Mail.

EXEC msdb.dbo.sp_addrolemember @rolename = 'DatabaseMailUserRole'
    ,@membername = '<user or role name>';
GO

Upvotes: 1

Related Questions