Microsoft SQL Server on Windows Azure Virtual Machines

The writers of this blog are a part of the Microsoft SQL Server team. We will be blogging about our tools, scripts, webcasts, and miscellaneous tips that will help you get the most out of SQL Server components on Windows Azure Virtual machines

SQL Database Mail -- Send Emails in HTML Format

SQL Database Mail -- Send Emails in HTML Format

  • Comments 2

Usually the content of emails is sent by Database Mail in a plain text.  You can change it to HTML format for a richer content.  This article demonstrates how to do it.

The article here is assumed that a SQL Database Mail profile "MailProfile1' has been created.  The MailProfile1 tells Database Mail what account it should use to send emails.  For how to create a Database Mail profile, you can refer to the previous post SQL Database Mail - Send Emails from SQL Server.

Here is the example to send emails in HTML format.

-- Start T-SQL

    USE msdb
    EXEC sp_send_dbmail
      @profile_name = 'MailProfile1',
      @recipients = 'someone@microsoft.com',
      @subject = 'HTML Format',
      @body_format = 'HTML',
      @body = '<html><body><p>An html link to www.bing.com is embedded in this email. The link is here: <a href="http://www.bing.com">u bing?</a></p></body></html>'
     

-- End T-SQL --

The recipient will receive an email like the following one.

From: Yuhong Li
Sent: Wednesday, January 05, 2011 12:09 PM
To: Some One
Subject: HTML Format

An html link to www.bing.com is embedded in this email. The link is here: u bing?

Click on the word "u bing?" in the email, it will redirect readers to http://www.bing.com.

For more information about sending emails, see sp_send_dbmail in MSDN documents.

<END OF POST>

 

Leave a Comment
  • Please add 4 and 6 and type the answer here:
  • Post
  • is there a size limitation for the body of the html email?  There is with SQLMail

  • Hi,

    The mail body gets formatted, but how to format the table in which output of query are appearing. They comes by default in Times new roman, and i want to change this to verdana.

Page 1 of 1 (2 items)