Aquí está un buen ejemplo en los sqltips -
http://www.mssqltips.com/tip.asp?tip=1100 Y aquí está un acercamiento con guión.
-- Crear un perfil del correo de la base de datos
EJECUTAR msdb.dbo.sysmail_add_profile_sp
@profile_name = “SQL2005_Email_ProfileName
”,
@description = “servicio de la notificación para el servidor del SQL”;
-- Crear una cuenta del correo de la base de datos
EJECUTAR msdb.dbo.sysmail_add_account_sp
@account_name = “servicio de la notificación del servidor del SQL”,
@description = “servicio de la notificación del servidor del SQL”,
@email_address = “john.doe@domain_name.com”
,
@replyto_address = “john.doe@domain_name.com”
,
@display_name = “servicio de la notificación del servidor del SQL”,
@mailserver_name = “smtpserver.domain_name.com
”;
-- Agregar la cuenta al perfil
EJECUTAR msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = “SQL2005_Email_ProfileName
”,
@account_name = “servicio de la notificación del servidor del SQL”,
@sequence_number =1;
-- Acceso de Grant al perfil al papel de DBMailUsers
EJECUTAR msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = “SQL2005_Email_ProfileName
”,
@principal_id = 0,
@is_default = 1;
SELECCIONAR * de msdb.dbo.sysmail_profile
SELECCIONAR * de msdb.dbo.sysmail_account
para probar:
sp_send_dbmail [[@profile_name =] “profile_name”]
[, [@recipients =] “recipientes [; … n]”]
[, [@copy_recipients =] “copy_recipient [; … n]”]
[, [@blind_copy_recipients =] “blind_copy_recipient [; … n]”]
[, [@subject =] “tema”]
[, [@body =] “cuerpo”]
[, [@body_format =] “body_format”]
[, [@importance =] “importancia”]
[, [@sensitivity =] “sensibilidad”]
[, [@file_attachments =] “accesorio [; … n]”]
[, [@query =] “pregunta”]
[, [@execute_query_database =] “execute_query_database”]
[, [@attach_query_result_as_file
=] attach_query_result_as_file
]
[, [@query_attachment_filename
=] query_attachment_filename]
[, [@query_result_header =] query_result_header]
[, [@query_result_width =] query_result_width]
[, [@query_result_separator =] “query_result_separator”]
[, [@exclude_query_output =] exclude_query_output]
[, [@append_query_error =] append_query_error]
[, [@query_no_truncate =] query_no_truncate]
[, [@query_result_no_padding =] el query_result_no_padding]
[, [@mailitem_id =] mailitem_id] [SALIDA]
Aclamaciones,
Hades666