Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to send E-mail from SQL Server 2008. What are the basic steps for that? Can you explain me if someone used this facility.

Any help will appreciated.

this link will helpful as commented by marc_s (also I have accepted an answer below)

share|improve this question

migrated from Jan 5 '12 at 12:01

This question came from our site for professional and enthusiast programmers.

@idstam How to move the same Question from SO to other? – M.S.Nayak Jan 5 '12 at 5:28
There are many articles out there – gbn Jan 5 '12 at 5:58
See:… - use the new, current "SQLMail" facilities - not old, deprecated solutions like "DatabaseMail" or even "Outlook activation" – marc_s Jan 5 '12 at 6:12
@marc_s Thanks Very usefull blog post.... – M.S.Nayak Jan 5 '12 at 6:50
@marc_s: DB Mail is new, SQL Mail is legacy... – gbn Jan 5 '12 at 12:03
up vote 3 down vote accepted

In management studio configure the database mail option under "Management" (both the account and the profile) and then use the stored procedure sp_send_dbmail in the msdb database.

share|improve this answer
  1. In SSMS object Explorer, click Management
  2. Right-click Database Mail
  3. Click Configure Database Mail

enter image description here

4.Select Set up Database Mail by performing the following tasks

enter image description here

5.Enter a profile name and click Add

enter image description here

6.Enter the settings for your email account. I could not set the account for my company's email account - it just didn't work. But I had no trouble with setting the Gmail account I use and these are the parameters that you should use for the Server name and Port number

enter image description here

It is not possible to send attachments from SSMS, you have to use T-SQL for that:

EXEC msdb.dbo.sp_send_dbmail
@profile_name='carol Gmail',
@subject='Test email',
@body='Attachment test',
share|improve this answer
I got the following error log. The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2013-07-30T12:18:14). Exception Message: Cannot send mails to mail server. (The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. bs3sm81108080pbc.42 - gsmtp). ),5848,4,,7/30/2013 12:18:14 PM,sa. Pls help what are the prerequisites to configure this services. – JP Chauhan Jul 30 '13 at 6:54

THe below is the query for send email

EXEC msdb.dbo.sp_send_dbmail @profile_name = 'MyDomain_EmailProfile', @from_address = '', @recipients = 'your to address', @copy_recipients = 'your cc', @subject = 'Subject here', @body = 'Mail content here', @body_format = 'HTML';

To know more detail about SQL email, you can check here. Steps to send mail using sql server:

share|improve this answer
Please edit your answer with details (link only answers are not encouraged here, as links may become obsolete.) – ypercubeᵀᴹ Jan 12 '14 at 17:39
It is OK to link to your own blog but have to add at least a brief description of your suggestion, here. – ypercubeᵀᴹ Jan 12 '14 at 17:40

Try the following SP.

CREATE procedure [dbo].[usp_send_cdosysmail]
@from varchar(500) ,
@to varchar(500) ,
@subject varchar(500),
@body varchar(max) ,
@smtpserver varchar(25),
@bodytype varchar(10) 
declare @imsg int
declare @hr int
declare @source varchar(255)
declare @description varchar(500)
declare @output varchar(1000)
exec @hr = sp_oacreate 'cdo.message', @imsg out
exec @hr = sp_oasetproperty @imsg,

exec @hr = sp_oasetproperty @imsg, 'configuration.fields("").value', @smtpserver 

exec @hr = sp_oamethod @imsg, 'configuration.fields.update', null
exec @hr = sp_oasetproperty @imsg, 'to', @to
exec @hr = sp_oasetproperty @imsg, 'from', @from
exec @hr = sp_oasetproperty @imsg, 'subject', @subject

-- if you are using html e-mail, use 'htmlbody' instead of 'textbody'.

exec @hr = sp_oasetproperty @imsg, @bodytype, @body
exec @hr = sp_oamethod @imsg, 'send', null

-- sample error handling.
if @hr <>0 
select @hr
exec @hr = sp_oageterrorinfo null, @source out, @description out
if @hr = 0
select @output = ' source: ' + @source
print @output
select @output = ' description: ' + @description
print @output
print ' sp_oageterrorinfo failed.'
exec @hr = sp_oadestroy @imsg
share|improve this answer
Thanks for response. Can I include File attachment option? If How? – M.S.Nayak Jan 5 '12 at 6:03
Way too complicated, way too risky (using the "sp_OA" stuff) and totally not necessary to do it this complicated..... just use the built-in SQL Server "SQLMail" - see how here:… – marc_s Jan 5 '12 at 6:13
-1 this is so dated and obsolete. If you can use CDO you can use DatabaseMail because it is SMTP based – gbn Jan 5 '12 at 12:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.