Etapa 1) Criar perfil e conta
Você precisa criar um perfil e uma conta usando o Assistente para Configurar Database Mail, que pode ser acessado no menu de contexto Configurar Database Mail do nó Database Mail no Nó de Gerenciamento. Esse assistente é usado para gerenciar contas, perfis e configurações globais do Database Mail.
Etapa 2)
CORRER:
sp_CONFIGURE 'show advanced', 1
GO
RECONFIGURE
GO
sp_CONFIGURE 'Database Mail XPs', 1
GO
RECONFIGURE
GO
Etapa 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.'
Para percorrer a tabela
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
Postei isso no link a seguir http://ms-sql-queries.blogspot.in/2012/12/how-to-send-email-from-sql-server.html