martes, 23 de octubre de 2012

Send mail in SQL

--send mail using sql agent

exec sp_configure 'show advanced option', '1'
reconfigure
exec sp_configure 'SQL Mail XPs', 1
reconfigure

exec sys.xp_startmail
exec master.sys.xp_sendmail @recipients=N'tucorreo@gmail.com', @message=N'xp_sendmail test.'
exec sys.xp_stopmail

--run exe

exec sp_configure 'show advanced option', '1'
reconfigure
exec sp_configure 'xp_cmdshell', 1
reconfigure
exec sp_configure 'show advanced option', '0'
reconfigure

EXEC xp_cmdshell 'c:\MailEngine.exe'