Solved

format @body in sp_send_dbmail

Posted on 2009-04-07
4
1,395 Views
Last Modified: 2012-06-27
I am calling sp_send_dbmail from within a stored procedure.  I am getting the content of @body from a field in a database.  I would like the body of the message to be formatted with as though the email had been typed.  I need to have the proper line feeds, bolding etc.  Does anyone know how to do this?

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQLServerDatabaseMailProfile',
@recipients = @recipients,
@body = @mymsg,
@subject = 'my subject'
0
Comment
Question by:spmcmorrow
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
aaronakin earned 500 total points
ID: 24092196
You'll need to format the body as HTML and add @body_format = 'HTML' to the procedure.
0
 

Author Comment

by:spmcmorrow
ID: 24097678
Ok, I just need a few details cleared up. I need to store the body of the message in a field (ideally I would like the user to be able to edit that message body..but that is second)  I need to take that message and customize it based on my data.  I should be able to do that.  

But what type of field in MS SQL do I store the html in.  I tried entering it in a varchar field and it didn't like all the special characters.  
0
 
LVL 11

Expert Comment

by:aaronakin
ID: 24098198
Varchar field should be fine.  The script below will give you an example.

CREATE TABLE #Test (HtmlText VARCHAR(5000))
 

INSERT INTO #Test VALUES ('<html><body><p>This is html text</p></body></html>')
 

SELECT HtmlText FROM #Test
 

DROP TABLE #Test

Open in new window

0
 

Author Closing Comment

by:spmcmorrow
ID: 31567742
Thank you.  You answered the question I asked.  Now I have a few more, but I can ask them separately.  Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now