Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. --
  2. -- Configure configs
  3. --
  4. USE [master];
  5. GO
  6.  
  7. sp_configure
  8. 'show advanced options',
  9. 1;
  10. GO
  11.  
  12. RECONFIGURE WITH OVERRIDE;
  13. GO
  14.  
  15. sp_configure
  16. 'Database Mail XPs',
  17. 1;
  18. GO
  19.  
  20. RECONFIGURE;
  21. GO
  22.  
  23. --
  24. -- Creating account
  25. --
  26. EXECUTE msdb.dbo.sysmail_add_account_sp
  27. @account_name='<account_name, nvarchar(100), Account>',
  28. @description='Mail account for Database Mail',
  29. @email_address='<email_address, nvarchar(100), email@domain.com>',
  30. @display_name='Account',
  31. @username='<username, nvarchar(100), email@domain.com>',
  32. @password='<password, nvarchar(100), ********>',
  33. @mailserver_name='<mailserver_name, nvarchar(100), smtp.gmail.com>',
  34. @port='<port, int, 587>';
  35. GO
  36.  
  37. --
  38. -- Creating profile
  39. --
  40. EXECUTE msdb.dbo.sysmail_add_profile_sp
  41. @profile_name='<profile_name, nvarchar(100), Profile>',
  42. @description='Profile needed for database mail';
  43. GO
  44.  
  45. --
  46. -- Creating profile account
  47. --
  48. EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
  49. @profile_name='<profile_name, nvarchar(100), Profile>',
  50. @account_name='<account_name, nvarchar(100), Account>',
  51. @sequence_number=1;
  52. GO
  53.  
  54. --
  55. -- Defining principal profile
  56. --
  57. EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
  58. @profile_name='<profile_name, nvarchar(100), Profile>',
  59. @principal_name='public',
  60. @is_default=1;
  61. GO
  62.  
  63. --
  64. -- Sending...
  65. --
  66. DECLARE
  67. @guid NVARCHAR(MAX)=NEWID( );
  68.  
  69. DECLARE
  70. @body1 VARCHAR(100);
  71.  
  72. SET @body1='Server: '+@@servername+' Test DB Email - Id :'+@guid;
  73.  
  74. EXEC msdb.dbo.sp_send_dbmail
  75. @recipients='<recipients, nvarchar(100), recipient@domain.com>',
  76. @subject='Test',
  77. @body=@body1,
  78. @body_format='HTML';
  79.  
  80. SELECT *
  81. FROM msdb.dbo.sysmail_event_log;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement