Send mail from sql
Declare @tablehtml nvarchar(max);
set @tablehtml =
N'<h1> Correo de Sistemas </h1>'+
N'<table border="1">'+
N'<tr><th> correo</th><th> nombre</th>'+
cast ((select fullname,mail
from employes
for XML PATH('tr'), Type
) as nvarchar (max) ) +
N'</table>';
execute msdb.dbo.sp_send_dbmail
@profile_name = '<<profile>>',
@recipients = 'username@email.com',
@body = @tablehtml,
@Body_format='HTML',
@execute_query_database='<<database>>',
@subject ='test',
@attach_query_result_as_file =0;