How to Setup Database Mail in SQL Server (SSMS)

This article shows you how to setup Database Mail for the first time on a new SQL Server installation.

As with many things SQL Server, you can configure Database Mail via the SSMS GUI, or you can do it using T-SQL code.

This article covers the SSMS GUI option. If you’re interested in the T-SQL option, see How to Send Email in SQL Server (T-SQL).

Continue reading

How to Fix “profile name is not valid” When Updating a Database Mail Profile in SQL Server (T-SQL)

If you’re getting a “profile name is not valid” error when updating a Database Mail profile in SQL Server, it could be that you’ve forgotten to provide the profile ID.

When you update a Database Mail profile with the sysmail_update_profile_sp stored procedure, you need to include the profile ID if you want to update the profile name.

Continue reading

Send Email from a Trigger in SQL Server (T-SQL)

If you find yourself needing to send an email automatically upon certain events occurring in SQL Server, you can do this via a trigger.

For example, you could automatically send an email when somebody deletes or updates a record from a table, etc.

To do this, you need to create a trigger that includes code for sending the email upon the required event.

Continue reading

Change the Separator to a Comma when Emailing Query Results in SQL Server (T-SQL)

If you’ve ever used SQL Server’s Database Mail to email the results of a query, you might have noticed that the results are separated by a space by default.

This is fine if you want a space-separated result set, but what if you want it to be comma-separated?

Fortunately you can use the @query_result_separator argument to do just that. You can use this argument to specify any separator (as long as it’s a char(1)).

Continue reading