Trin 1) Opret profil og konto
Du skal oprette en profil og konto ved hjælp af guiden Konfigurer databasemail, som du kan få adgang til fra kontekstmenuen Konfigurer databasemail i databasenoden i Management Node. Denne guide bruges til at administrere konti, profiler og globale indstillinger for Database Mail.
Trin 2)
KØR:
sp_CONFIGURE 'show advanced', 1
GO
RECONFIGURE
GO
sp_CONFIGURE 'Database Mail XPs', 1
GO
RECONFIGURE
GO
Trin 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.'
At gå gennem tabellen
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
Opgav dette på følgende link http://ms-sql-queries.blogspot.in/2012/12/how-to-send-email-from-sql-server.html