{"id":179819,"date":"2013-05-15T21:11:03","date_gmt":"2013-05-15T17:11:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=179819"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=179819","title":{"rendered":"<span class=\"post_title\">Database Mail: \u041f\u043e\u0447\u0442\u043e\u0432\u044b\u0435 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u043f\u0440\u044f\u043c\u043e \u0438\u0437 Microsoft SQL Server<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041c\u043d\u043e\u0433\u0438\u0435 \u0437\u043d\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 2005 \u0432 SQL Server \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u044b \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u0440\u043e\u0447\u043d\u044b\u0445 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0441\u0431\u043e\u0435 \u0437\u0430\u0434\u0430\u0447, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u043f\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044e. \u041e\u0434\u043d\u0430\u043a\u043e \u043b\u0438\u0448\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u0438\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u043f\u0438\u0441\u044c\u043c\u0430 \u0432 SQL Server \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u044f\u043c\u043e \u0438\u0437 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0445\u0440\u0430\u043d\u0438\u043c\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440. \u0418 \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0443\u0436\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0443 \u0432 SQL Server, \u0442\u043e \u043d\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u043f\u0438\u0441\u044c\u043c\u0430 \u0443 \u0432\u0430\u0441 \u0443\u0439\u0434\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u043c\u0438\u043d\u0443\u0442\u0430, \u0430 \u0446\u0435\u043b\u0443\u044e \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430 15-20 \u043c\u0438\u043d\u0443\u0442. \u041d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 Database Mail (DBMail), \u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430<\/h4>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u0441 DBMail \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043d\u0435\u0439 \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442 (SMTP), \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043f\u0438\u0441\u044c\u043c\u0430. \u0420\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 IMAP \u0441\u0438\u0441\u0442\u0435\u043c\u0430, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435 \u0443\u043c\u0435\u0435\u0442, \u043d\u043e \u044d\u0442\u043e \u0432 \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p>  \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 DBMail \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 SQL Server \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"http:\/\/habrahabr.ru\/post\/132902\/\">\u00ab\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Database Mail \u0432 MS SQL Server 2005 \u0438 \u0441\u0442\u0430\u0440\u0448\u0435\u00bb<\/a>, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f. \u0414\u0443\u043c\u0430\u044e, \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u0435\u043d \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0432\u043f\u0435\u0440\u0432\u044b\u0435.<\/p>\n<p>  \u042f, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u043a\u0430\u0436\u0443 \u0441\u0435\u0439\u0447\u0430\u0441 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442: \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e, \u0447\u0435\u0440\u0435\u0437 SQL-\u0441\u043a\u0440\u0438\u043f\u0442. \u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435 \u0442\u0430\u043a \u043d\u0430\u0433\u043b\u044f\u0434\u0435\u043d, \u043d\u043e \u043e\u043d \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0442\u0435\u043c, \u043a\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 DBMail \u043d\u0430 \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 \u043d\u043e\u0432\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u0412\u0430\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c, \u0447\u0442\u043e \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0438\u0436\u0435\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u0439\u0442\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u043a\u0430\u043a \u0447\u043b\u0435\u043d \u0433\u0440\u0443\u043f\u043f\u044b sysadmin, \u0438\u043d\u0430\u0447\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0443\u043a\u0430\u0436\u0435\u0442 \u043d\u0430 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u043f\u0440\u0430\u0432.<\/p>\n<p>  \u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u043a \u0434\u0435\u043b\u0443. \u0412\u043e\u0442 \u0441\u043a\u0440\u0438\u043f\u0442, \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f DBMail:  <\/p>\n<pre><code class=\"sql\">-- \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u043a\u043b\u044e\u0447\u0438\u043c Service broker - \u043e\u043d \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 -- \u043f\u0438\u0441\u0435\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 DBMail IF (SELECT is_broker_enabled FROM sys.databases WHERE [name] = 'msdb') = 0 \tALTER DATABASE msdb SET ENABLE_BROKER WITH ROLLBACK AFTER 10 SECONDS GO -- \u0412\u043a\u043b\u044e\u0447\u0438\u043c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 DBMail sp_configure 'Database Mail XPs', 1 GO RECONFIGURE GO <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430 \u043b\u0438 \u0441\u043b\u0443\u0436\u0431\u0430 DBMail:  <\/p>\n<pre><code class=\"sql\">EXECUTE msdb.dbo.sysmail_help_status_sp <\/code><\/pre>\n<p>  \u0418 \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043d\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430 (\u0435\u0435 \u0441\u0442\u0430\u0442\u0443\u0441 \u043d\u0435 \u00abSTARTED\u00bb), \u0442\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c  <\/p>\n<pre><code class=\"sql\">EXECUTE msdb.dbo.sysmail_start_sp <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c SMTP-\u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u0434\u043b\u044f \u043e\u0442\u0441\u044b\u043b\u043a\u0438 \u043f\u0438\u0441\u0435\u043c, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0445 \u0440\u0430\u0441\u0441\u044b\u043b\u043e\u043a \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c SMTP-\u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u043a \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0444\u0438\u043b\u044e. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0443 \u0441\u0430\u0439\u0442\u0430 MySite.ru \u043d\u0443\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0447\u0442\u043e\u0432\u0443\u044e \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0443 \u0434\u043b\u044f \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430, \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0432\u043e\u0439 \u044f\u0449\u0438\u043a admin@mysite.ru \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 smtp.mysite.ru.  <\/p>\n<pre><code class=\"sql\">-- \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c SMTP-\u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u0434\u043b\u044f \u043e\u0442\u0441\u044b\u043b\u043a\u0438 \u043f\u0438\u0441\u0435\u043c EXECUTE msdb.dbo.sysmail_add_account_sp \t-- \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \t\t@account_name = 'admin@mysite.ru', \t-- \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \t\t@description = N'\u041f\u043e\u0447\u0442\u043e\u0432\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442 admin@mysite.ru', \t-- \u041f\u043e\u0447\u0442\u043e\u0432\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \t\t@email_address = 'admin@mysite.ru', \t-- \u0418\u043c\u044f, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u043e\u0435 \u0432 \u043f\u0438\u0441\u044c\u043c\u0435 \u0432 \u043f\u043e\u043b\u0435 &quot;\u041e\u0442:&quot; \t\t@display_name = N'\u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440 MySite.ru', \t-- \u0410\u0434\u0440\u0435\u0441, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044e \u043f\u0438\u0441\u044c\u043c\u0430 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \t-- \u0415\u0441\u043b\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0438\u0448\u0443\u0442 &quot;no-reply&quot; \t\t@replyto_address = 'no-reply@please.no-reply', \t-- \u0414\u043e\u043c\u0435\u043d \u0438\u043b\u0438 IP-\u0430\u0434\u0440\u0435\u0441 SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \t\t@mailserver_name = 'smtp.mysite.ru', \t-- \u041f\u043e\u0440\u0442 SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043e\u0431\u044b\u0447\u043d\u043e 25 \t\t@port = 25, \t-- \u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0433\u043e \t-- \u0430\u0434\u0440\u0435\u0441\u0430 \u043f\u043e\u0447\u0442\u043e\u0432\u043e\u0433\u043e \u044f\u0449\u0438\u043a\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \t\t@username = 'admin', \t-- \u041f\u0430\u0440\u043e\u043b\u044c \u043a \u043f\u043e\u0447\u0442\u043e\u0432\u043e\u043c\u0443 \u044f\u0449\u0438\u043a\u0443 \t\t@password = 'MyPassword', \t-- \u0417\u0430\u0449\u0438\u0442\u0430 SSL \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0441\u0435\u0439\u0447\u0430\u0441 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 SSL \t\t@enable_ssl = 1; -- \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0445 \u0440\u0430\u0441\u0441\u044b\u043b\u043e\u043a EXECUTE msdb.dbo.sysmail_add_profile_sp \t\t@profile_name = 'MySite Admin Mailer'; -- \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c SMTP-\u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0444\u0438\u043b\u044e EXECUTE msdb.dbo.sysmail_add_profileaccount_sp \t\t@profile_name = 'MySite Admin Mailer', \t\t@account_name = 'admin@mysite.ru', \t-- \u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u043e\u043c\u0435\u0440\u0430 SMTP-\u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u043f\u0440\u043e\u0444\u0438\u043b\u0435 \t\t@sequence_number = 1; -- \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0440\u043e\u0444\u0438\u043b\u044e \u0434\u043b\u044f \u0440\u043e\u043b\u0438 DatabaseMailUserRole \u0431\u0430\u0437\u044b MSDB EXECUTE msdb.dbo.sysmail_add_principalprofile_sp \t\t@profile_name = 'MySite Admin Mailer', \t\t@principal_id = 0, \t\t@is_default = 1; <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0430\u0440\u0443 SMTP-\u0430\u043a\u043a\u0430\u0443\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0445 \u0441\u043b\u0443\u0436\u0431 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0445 \u043a \u043f\u0440\u043e\u0444\u0438\u043b\u044e. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432\u0430\u0436\u043d\u043e\u0435 \u043f\u0438\u0441\u044c\u043c\u043e \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u0432\u044f\u0437\u0438 \u0441 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u043e\u0433\u043e SMTP-\u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 @sequence_number \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b sysmail_add_profileaccount_sp \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0432\u043d\u044f\u0442\u044c\u0441\u044f 1 (\u0441\u043c. \u0432\u044b\u0448\u0435), \u0434\u043b\u044f \u0437\u0430\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0432\u043d\u044f\u0442\u044c\u0441\u044f 2.<\/p>\n<p>  \u041e\u0447\u0435\u043d\u044c \u043c\u0430\u0441\u0441\u043e\u0432\u044b\u0435 \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0435 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0441 \u044f\u0449\u0438\u043a\u0430 \u0447\u0430\u0441\u0442\u043d\u043e\u0433\u043e \u0434\u043e\u043c\u0435\u043d\u0430. \u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u0441 \u044f\u0449\u0438\u043a\u043e\u0432 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u043e\u0432 (\u044f\u0449\u0438\u043a\u043e\u0432 \u043d\u0430 yandex.ru, mail.ru, gmail.com \u0438 \u0442. \u0434.) SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0441\u0447\u0435\u0441\u0442\u044c \u0432\u0430\u0441 \u0441\u043f\u0430\u043c\u0435\u0440\u043e\u043c \u0438 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0443 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u0435\u0441\u044c \u044f\u0449\u0438\u043a.<\/p>\n<h4>\u0411\u0440\u0430\u043d\u0434\u043c\u0430\u0443\u044d\u0440<\/h4>\n<p>  \u041d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043f\u0438\u0441\u0435\u043c \u0432 SQL Server \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430. \u0412 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 SQL Server \u043e\u043d\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00abDatabaseMail90.exe\u00bb \u0438\u043b\u0438 \u00abDatabaseMail.exe\u00bb \u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 \u00abC:\\Program Files\\Microsoft SQL Server\\&#8230;\\MSSQL\\Binn\\\u00bb. \u0412\u0430\u0436\u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0434\u043b\u044f \u043d\u0435\u0435 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0442\u0440\u0430\u0444\u0438\u043a \u0432 \u0431\u0440\u0430\u043d\u0434\u043c\u0430\u0443\u044d\u0440\u0435 (\u0444\u0430\u0439\u0440\u0432\u043e\u043b\u0435).<\/p>\n<h4>\u0422\u0435\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u0438\u0441\u044c\u043c\u043e<\/h4>\n<p>  \u041f\u043e\u0440\u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c, \u0432\u0441\u0435 \u043b\u0438 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435. \u041e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0438\u0441\u044c\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u043b\u044e\u0431\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u0437 \u0433\u0440\u0443\u043f\u043f\u044b sysadmin, \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u0431\u0430\u0437\u044b (db_owner) MSDB \u0438\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441 \u0440\u043e\u043b\u044c\u044e DatabaseMailUserRole. \u0414\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0440\u043e\u043b\u0438 DatabaseMailUserRole \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 sp_addrolemember:  <\/p>\n<pre><code class=\"sql\">sp_addrolemember \t\t@rolename = 'DatabaseMailUserRole', \t\t@membername = '&lt;\u0438\u043c\u044f_\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f&gt;'; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u0438\u0441\u044c\u043c\u043e:  <\/p>\n<pre><code class=\"sql\">EXEC msdb.dbo.sp_send_dbmail \t-- \u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0445 \u0440\u0430\u0441\u0441\u044b\u043b\u043e\u043a \t\t@profile_name = 'MySite Admin Mailer', \t-- \u0410\u0434\u0440\u0435\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044f \t\t@recipients = 'friend@mysite.ru', \t-- \u0422\u0435\u043a\u0441\u0442 \u043f\u0438\u0441\u044c\u043c\u0430 \t\t@body = N'\u0418\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b SQL Server Database Mail', \t-- \u0422\u0435\u043c\u0430 \t\t@subject = N'\u0422\u0435\u0441\u0442\u043e\u0432\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435', \t-- \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a \u043f\u0438\u0441\u044c\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \t\t@query = 'SELECT TOP 10 name FROM sys.objects'; <\/code><\/pre>\n<p>  \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b sp_send_dbmail \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0435\u0435 <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190307(v=sql.105).aspx\">\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0432 MSDN<\/a>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0442\u0430\u0442\u0443\u0441 \u043f\u0438\u0441\u044c\u043c\u0430:  <\/p>\n<pre><code class=\"sql\">SELECT * FROM msdb.dbo.sysmail_allitems <\/code><\/pre>\n<p>  \u0410 \u0437\u0430\u0442\u0435\u043c \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u043b\u043e\u0433:  <\/p>\n<pre><code class=\"sql\">SELECT * FROM msdb.dbo.sysmail_event_log <\/code><\/pre>\n<p>  \u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 MSDN <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms188663(v=sql.105).aspx\">\u00abTroubleshooting Database Mail\u00bb<\/a>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"http:\/\/dbatasks.blogspot.co.uk\/2012\/11\/troubleshooting-database-mail-part-ii.html\">\u00abSQL Server tasks for DBAs: Troubleshooting Database Mail\u00bb<\/a>.<\/p>\n<p>  \u0423\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0430\u043a\u0438\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c:  <\/p>\n<pre><code class=\"sql\">SELECT sent_account_id, sent_date FROM msdb.dbo.sysmail_sentitems <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041f\u043e\u0447\u0442\u043e\u0432\u0430\u044f \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0430<\/h4>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0443 \u0441\u0430\u0439\u0442\u0430 MySite.ru \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430 \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0435 \u0437\u0430\u0445\u043e\u0434\u0438\u043b \u043d\u0430 \u0441\u0430\u0439\u0442 \u0431\u043e\u043b\u0435\u0435 \u0433\u043e\u0434\u0430, \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438\u043c \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044f. \u041c\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0443\u044e \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 DBMail \u0438 SQL, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043a\u0443\u0440\u0441\u043e\u0440\u044b \u0438 \u0446\u0438\u043a\u043b\u044b. \u0414\u043b\u044f \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0439:  <\/p>\n<ul>\n<li>\u041f\u0438\u0441\u044c\u043c\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u0442\u0435\u043c, \u043a\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u043b \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u0447\u0442\u043e \u043d\u0435 \u0436\u0435\u043b\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043f\u0438\u0441\u044c\u043c\u0430. \u0414\u043b\u044f \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043e\u0442\u043a\u0430\u0437\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0446\u0438\u043a\u043b\u0435.<\/li>\n<li>\u041f\u0438\u0441\u044c\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u044b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 HTML.<\/li>\n<li>\u041f\u0438\u0441\u044c\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u0441 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u043c \u0432 3 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043d\u0430\u0448 SMTP-\u0441\u0435\u0440\u0432\u0435\u0440.<\/li>\n<li>\u0420\u0430\u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u043d\u0430\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 SQL-\u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u0430, \u0441\u043a\u0430\u0436\u0435\u043c, \u0432 3 \u0447\u0430\u0441\u0430 \u043d\u043e\u0447\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"sql\">-- \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 mysite USE mysite GO -- \u041e\u0431\u044a\u044f\u0432\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435: \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0438\u043c\u044f, -- \u0434\u0430\u0442\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0432\u0445\u043e\u0434\u0430 \u043d\u0430 \u0441\u0430\u0439\u0442, \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \tDECLARE @user_id int, @user_name nvarchar(255), @last_login_date smalldatetime, \t\t@email_address varchar(255); -- \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f @body \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043f\u0438\u0441\u044c\u043c\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 HTML \tDECLARE @body nvarchar(MAX); -- \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f @no_mail \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043e\u0442\u043a\u0430\u0437\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u043e\u0442 \u0440\u0430\u0441\u0441\u044b\u043b\u043e\u043a \tDECLARE @no_mail int; -- \u041e\u0431\u044a\u044f\u0432\u0438\u043c \u043a\u0443\u0440\u0441\u043e\u0440 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u0443\u0440\u0441\u043e\u0440 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c -- \u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0436\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u0443\u0440\u0441\u043e\u0440\u0430 FAST_FORWARD \tDECLARE users CURSOR LOCAL FAST_FORWARD FOR \t\tSELECT id, name, last_login_date, email_address \t\tFROM users \t\tWHERE user_role IN (3,4,5) \t\t\tAND account_state = 2 \t\t\tAND email_address IS NOT NULL \t\t\tAND DATEDIFF(day, last_login_date, GETDATE()) &gt; 365 \t\tORDER BY id -- \u041f\u0443\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u0430\u044f \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430\u0447\u043d\u0435\u0442\u0441\u044f \u043d\u0435 \u0441\u0435\u0439\u0447\u0430\u0441, \u0430 \u0432 3 \u0447\u0430\u0441\u0430 \u043d\u043e\u0447\u0438 \tWAITFOR TIME '03:00:00' -- \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043a\u0443\u0440\u0441\u043e\u0440 users \tOPEN users -- \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u044f\u0434 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0438\u0437 \u043a\u0443\u0440\u0441\u043e\u0440\u0430 \tFETCH NEXT FROM users INTO @user_id, @user_name, @last_login_date, @email_address -- \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0446\u0438\u043a\u043b \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 WHILE @@FETCH_STATUS = 0 BEGIN \t-- \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c, \u043d\u0435 \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043e\u0442 \u0440\u0430\u0441\u0441\u044b\u043b\u043e\u043a \t\tSET @no_mail = (SELECT id FROM users WHERE id = @user_id AND allow_mail = 0) \t-- \u0415\u0441\u043b\u0438 \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f, \u0442\u043e \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \t\tIF @no_mail IS NOT NULL \t\t\tBEGIN \t\t\t\tPRINT N'\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c ' + @user_name + N' \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043e\u0442 \u0440\u0430\u0441\u0441\u044b\u043b\u043e\u043a.' \t\t\t\tFETCH NEXT FROM users INTO @user_id, @user_name, @last_login_date, @email_address \t\t\t\tCONTINUE \t\t\tEND  \t\tPRINT N'\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u0438\u0441\u044c\u043c\u0430 \u0434\u043b\u044f ' + @email_address + N' ...'  \t-- \u0421\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u043f\u0438\u0441\u044c\u043c\u0430 \t\tSET @body = N' &lt;html&gt; &lt;head&gt; &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=utf-8&quot;\/&gt; &lt;title&gt;\u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt; &lt;p&gt;&lt;img style=&quot;float:right;&quot; src=&quot;http:\/\/mysite.ru\/images\/logo.png&quot;\/&gt;&lt;\/p&gt; &lt;p&gt;\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, ' + @user_name + N'!&lt;\/p&gt; &lt;p&gt;\u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0412\u0430\u0441 \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u044c \u0441\u0430\u0439\u0442 MySite.ru. \u0423 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043c\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u043e\u0441\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435, \u0438 \u043c\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0438\u043b\u0438 \u043c\u043d\u043e\u0433\u043e \u0443\u0441\u0438\u043b\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0412\u0430\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0430\u0439\u0442\u043e\u043c.&lt;\/p&gt; &lt;p&gt;\u0416\u0435\u043b\u0430\u0435\u043c \u0443\u0441\u043f\u0435\u0445\u043e\u0432!&lt;\/p&gt; &lt;p&gt;\u0421 \u0443\u0432\u0430\u0436\u0435\u043d\u0438\u0435\u043c, \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u0430\u0439\u0442\u0430 MySite.ru&lt;\/p&gt; &lt;\/body&gt; &lt;\/html&gt;';  \t-- \u041e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u043f\u0438\u0441\u044c\u043c\u043e \t\tEXEC msdb.dbo.sp_send_dbmail \t\t\t@recipients = @email_address, \t\t\t@subject = N'\u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0412\u0430\u0441 \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u044c \u0441\u0430\u0439\u0442 MySite.ru', \t\t\t@body = @body, \t\t-- \u0424\u043e\u0440\u043c\u0430\u0442 \u043f\u0438\u0441\u044c\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0431\u043e 'HTML', \u043b\u0438\u0431\u043e 'TEXT' \t\t\t@body_format = 'HTML', \t\t-- \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043a \u043f\u0438\u0441\u044c\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u0444\u0430\u0439\u043b \t\t\t--@file_attachments ='C:\\attachment.jpg', \t\t-- \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0430\u0434\u0440\u0435\u0441 \u0434\u043b\u044f \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043f\u0438\u0438 \t\t\t--@copy_recipients ='me@gmail.com', \t\t-- &quot;Blind copy&quot; \u0438\u043b\u0438 &quot;carbon copy&quot; - \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043a\u043e\u043f\u0438\u0438 \u043f\u0438\u0441\u044c\u043c\u0430, \t\t-- \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u0432\u0438\u0434\u044f\u0442 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043e\u043f\u0438\u0439 \t\t\t--@blind_copy_recipients ='me2@gmail.com', \t\t-- \u0423\u043a\u0430\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0440\u0430\u043d\u0435\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0445 \u0440\u0430\u0441\u0441\u044b\u043b\u043e\u043a \t\t\t@profile_name = 'MySite Admin Mailer';  \t-- \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432 3 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043c\u0435\u0436\u0434\u0443 \u043f\u0438\u0441\u044c\u043c\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c SMTP-\u0441\u0435\u0440\u0432\u0435\u0440 \t\tWAITFOR DELAY '00:00:03'; \t-- \u0412 \u043a\u043e\u043d\u0446\u0435 \u0446\u0438\u043a\u043b\u0430 \u0431\u0435\u0440\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u043a\u0443\u0440\u0441\u043e\u0440\u0430 \t\tFETCH NEXT FROM users INTO @user_id, @user_name, @last_login_date, @email_address END -- \u0417\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043a\u0443\u0440\u0441\u043e\u0440 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 CLOSE users GO <\/code><\/pre>\n<p>  \u0412\u0441\u0451 \u0433\u043e\u0442\u043e\u0432\u043e. \u041c\u043e\u0436\u043d\u043e \u0438\u0434\u0442\u0438 \u043e\u0442\u0434\u044b\u0445\u0430\u0442\u044c. \t\t\t \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/179819\/\"> http:\/\/habrahabr.ru\/post\/179819\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041c\u043d\u043e\u0433\u0438\u0435 \u0437\u043d\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 2005 \u0432 SQL Server \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u044b \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u0440\u043e\u0447\u043d\u044b\u0445 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0441\u0431\u043e\u0435 \u0437\u0430\u0434\u0430\u0447, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u043f\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044e. \u041e\u0434\u043d\u0430\u043a\u043e \u043b\u0438\u0448\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u0438\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u043f\u0438\u0441\u044c\u043c\u0430 \u0432 SQL Server \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u044f\u043c\u043e \u0438\u0437 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0445\u0440\u0430\u043d\u0438\u043c\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440. \u0418 \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0443\u0436\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0443 \u0432 SQL Server, \u0442\u043e \u043d\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u043f\u0438\u0441\u044c\u043c\u0430 \u0443 \u0432\u0430\u0441 \u0443\u0439\u0434\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u043c\u0438\u043d\u0443\u0442\u0430, \u0430 \u0446\u0435\u043b\u0443\u044e \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430 15-20 \u043c\u0438\u043d\u0443\u0442. \u041d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 Database Mail (DBMail), \u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-179819","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/179819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=179819"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/179819\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=179819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=179819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=179819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}