Langkah 1) Buat Profil dan Akun
Anda perlu membuat profil dan akun menggunakan Configure Database Mail Wizard yang dapat diakses dari menu konteks Configure Database Mail dari node Database Mail di Management Node. Wizard ini digunakan untuk mengelola akun, profil, dan pengaturan global Database Mail.
Langkah 2)
JALANKAN:
sp_CONFIGURE 'show advanced', 1
GO
RECONFIGURE
GO
sp_CONFIGURE 'Database Mail XPs', 1
GO
RECONFIGURE
GO
Langkah 3)
USE msdb
GO
EXEC sp_send_dbmail @profile_name='yourprofilename',
@recipients='[email protected]',
@subject='Test message',
@body='This is the body of the test message.
Congrates Database Mail Received By you Successfully.'
Untuk mengulang tabel
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<[email protected]_id
BEGIN
SELECT @email_id=email_id
FROM [email_adresses]
set @query='sp_send_dbmail @profile_name=''yourprofilename'',
@recipients='''[email protected]_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
Memposting ini di tautan berikut http://ms-sql-queries.blogspot.in/2012/12/how-to-send-email-from-sql-server.html