How to Remove a Database Mail Account from a Profile in SQL Server (T-SQL)

In SQL Server, you can use the sysmail_delete_profileaccount_sp stored procedure to remove a Database Mail account from a profile.

You can remove the account from a specific profile, or you can remove it from all profiles. You can also remove all accounts from a given profile.

The way it works is, you provide two arguments; the account name or its ID, and the profile name or its ID. If you omit the argument for the profile, the account is removed from all profiles. If you omit the argument for the account, then all accounts are removed from the profile.

Continue reading

Send Emails with Attachments in SQL Server (T-SQL)

SQL Server provides us with the ability to send emails via its Database Mail solution. This includes a bunch of stored procedures that facilitate the configuration and sending of emails.

To send an email, use the sp_send_dbmail stored procedure. This procedure accepts a bunch of optional arguments, one of which allows you to send attachments.

Actually, there are two arguments that enable you to send attachments. The one you use will depend on the context.

They are:

  • @file_attachments – Allows you to specify a file to attach to the email.
  • @attach_query_result_as_file – This is only applicable if you’re also using @query to email the results of a query.

Examples below.

Continue reading

How to Increase the Allowable Attachment Size When Sending Email in SQL Server (T-SQL)

When you use Database Mail to send emails with attachments, you’ll need to ensure that the attachment file size is within the allowable attachment file size.

If you need to send attachments that are larger than the attachment limit, you’ll need to increase that limit.

Fortunately, increasing the allowed attachment file size can be done with a single line of T-SQL code.

Continue reading