Solved

format @body in sp_send_dbmail

Posted on 2009-04-07
4
1,496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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