Send emails with SQL Server using Html files
Sending emails from MS SQL Server using the Database Mail is easy. Once the Database Mail is active and configured (see this blog for quick configuration) the emails can be send using the SQL script below: USE msdb GO EXEC sp_send_dbmail @profile_name='EmailProfile', @recipients='test@example.com', @subject='Test message', @body='This is a test message.' In cases where there is a need to send emails in html format - creating the content inside of SQL script is not so convenient. With the help of OPENROWSET function we can read the content of html file, which contains the properly formatted and tested html. For example below is the html file that we can easily open in the browser and validate it displays correctly the way we want. It contains the html and body tags which wraps the content that will be inserted into the email’s body. Test Email This is a test message Below is the SQL script which will send the emails by readi