Sending E-Mail w/ MS SQL Server
MS SQLIn my quest for something to write about I came across and old post I had on an internal company blog site I wrote a few months ago. I can't get in trouble for copying of myself right?
At any rate, sending email using MS SQL server is pretty easy. Note,
in order you send e-mail via MS SQL Server you must have Outlook loaded
on the machine. View some not so easy to understand directions here.
If
your MS SQL box was set up correctly chances are things are
already good to go. The emails will be sent using
the built in SQLDBA account. To test it out copy and paste the code
below.
Simple example, just sending a test to myself
EXEC master.dbo.xp_sendmail
@recipients= 'someaddress@somedomain.com',
@subject= 'test',
@message= 'test'
More complex example, send email with attached results
EXEC master.dbo.xp_sendmail
@recipients = 'someaddress@somedomain.com',
@query = 'SELECT * FROM Sometable',
@subject = 'Some Report',
@message = 'This is some report emailed from SQL',@attach_results = 'TRUE', @width = 250
Good Day!
Ryan




Loading....