Remove Padding When Sending Query Results in an Email from SQL Server (T-SQL)

When you use the sp_send_dbmail stored procedure to send emails from SQL Server, you have the option of adding query results to the email.

When you do this, you might find that unwanted padding has been added to some columns. Fortunately, you can eliminate this padding with the @query_result_no_padding argument.

Continue reading

Create a Default Public Profile for Database Mail in SQL Server (T-SQL)

When you use the sp_send_dbmail stored procedure to send emails in SQL Server, you would typically include the @profile_name argument to specify which profile to use.

However, if you omit this argument, sp_send_dbmail will use the default private profile for the current user. If the user does not have a default private profile, sp_send_dbmail will use the default public profile for the msdb database.

If none of these are configured, you’ll get the following error:

Continue reading

How to Change the Default Database Mail Profile for a User in SQL Server (T-SQL)

If you’ve already created an association between a principal and a Database Mail profile, but you now want to change whether the profile is the default profile for that user, you can do that with the sysmail_update_principalprofile_sp stored procedure.

When doing this, you need to provide the name or ID of both the user and the profile. This is because you need to specify exactly which profile/principal association you want to update.

Continue reading

How to Change the Sequence Number of a Database Mail Account within a Profile in SQL Server (T-SQL)

If you’ve already added a Database Mail account to a profile, but you now want to change the sequence number, you can do that with the sysmail_update_profileaccount_sp stored procedure.

When doing this, you need to provide the name or ID of both the account and the profile. This is because you need to specify exactly which profile/account association you want to update.

Continue reading

Find the Associations Between Database Mail Accounts and Database Principals in SQL Server (T-SQL)

In SQL Server, you can use the sysmail_help_principalprofile_sp stored procedure on the msdb database to retrieve a list of all associations between Database Mail accounts and database principals.

You can also return account info based on the principal name/ID or the profile name/ID.

Continue reading