चरण 1) प्रोफ़ाइल और खाता बनाएं
आपको कॉन्फ़िगर डेटाबेस मेल विज़ार्ड का उपयोग करके एक प्रोफ़ाइल और खाता बनाने की आवश्यकता है जिसे प्रबंधन नोड में डेटाबेस मेल नोड के कॉन्फ़िगर डेटाबेस मेल संदर्भ मेनू से एक्सेस किया जा सकता है। इस विज़ार्ड का उपयोग खातों, प्रोफाइल और डेटाबेस मेल वैश्विक सेटिंग्स को प्रबंधित करने के लिए किया जाता है।
चरण 2)
भागो:
sp_CONFIGURE 'show advanced', 1
GO
RECONFIGURE
GO
sp_CONFIGURE 'Database Mail XPs', 1
GO
RECONFIGURE
GO
चरण 3)
USE msdb
GO
EXEC sp_send_dbmail @profile_name='yourprofilename',
@recipients='example@sqldat.com',
@subject='Test message',
@body='This is the body of the test message.
Congrates Database Mail Received By you Successfully.'
तालिका के माध्यम से लूप करने के लिए
DECLARE @email_id NVARCHAR(450), @id BIGINT, @max_id BIGINT, @query NVARCHAR(1000)
SELECT @id=MIN(id), @max_id=MAX(id) FROM [email_adresses]
WHILE @id<example@sqldat.com_id
BEGIN
SELECT @email_id=email_id
FROM [email_adresses]
set @query='sp_send_dbmail @profile_name=''yourprofilename'',
@recipients='''example@sqldat.com_id+''',
@subject=''Test message'',
@body=''This is the body of the test message.
Congrates Database Mail Received By you Successfully.'''
EXEC @query
SELECT @id=MIN(id) FROM [email_adresses] where id>@id
END
इसे निम्न लिंक पर पोस्ट किया गया है https://ms-sql-queries.blogspot.in/2012/12/how-to-send-email-from-sql-server.html