In this video, I have explained how to configure and send email using SQL Server.
Steps:-
1) Unblock SQL server to send email.
USE MASTER
GO
SP_CONFIGURE 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GO
SP_CONFIGURE 'Database Mail XPs', 1
RECONFIGURE WITH OVERRIDE
GO
SP_CONFIGURE 'show advanced options', o
RECONFIGURE WITH OVERRIDE
GO
2)Add mail account to SQL Server.
EXEC msdb.dbo.sysmail_add_account_sp
@account_name = 'xyz_Mail_Account'
, @description = 'Send mails through SQL Server'
, @email_address = 'Your Email ID'
, @display_name = 'xyz'
, @replyto_address = 'Your Email ID'
, @mailserver_name = 'Host Name'
, @username = 'Your Email ID'
, @password = 'Account Password'
, @port = 587
, @enable_ssl = 1
GO
EXEC msdb.dbo.sysmail_add_profile_sp@profile_name = 'xyz_Email_Profile',@description = 'Send emails using SQL Server'GO
EXEC msdb.dbo.sysmail_add_profileaccount_sp@profile_name = 'xyz_Email_Profile',@account_name = 'xyz_Mail_Account',@sequence_number = 1GO
EXEC msdb.dbo.sp_send_dbmail@profile_name = ' xyz_Email_Profile',@recipients = 'Recipient Email ID',@subject = 'Email from SQL Server',@body = 'This is my test email.',@importance = 'HIGH'GO
No comments:
Post a Comment