?
Solved

format @body in sp_send_dbmail

Posted on 2009-04-07
4
Medium Priority
?
1,707 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses

840 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