MSSQL İLE MAİL YOLLAMA ( msdb.dbo.sp_send_dbmail )

use msdb
go
dbo.sysmail_help_profile_sp        bu sorgu ile profil name öğreniyoruz. Sorgu sonucunda  çıkan profil name ile değişkenimize bu descriptionu veriyoruz.





declare @productName  nvarchar(max) ;
declare @categoryName  nvarchar(max) ;

select @productName=ProductName , @categoryName=CategoryName from Products p inner join Categories c on c.CategoryID=p.CategoryID where p.ProductID=8


declare @temp nvarchar(max)



Set @temp='Merhaba,
Bu bir mail gönderimidir...
<b>Kategori Adı :</b> '+@categoryName+'
<b>Ürün Adı :</b> '+@productName+'
Bilgilerinize sunar,
İyi çalışmalar dileriz.'




EXEC msdb.dbo.sp_send_dbmail     
-- @profile_name = 'Profil Name Yazınız ',
@recipients =  'oktayaltan72@gmail.com', -- Mai gidecek kişiler
@copy_recipients = ' ',    -- CC de olacak kişiler             
@subject = 'Test Maili',           
@body = @temp,                   
@body_format = 'HTML'



sorguyu çalıştırdığınızda  aşağıdaki hatayı alıyorsanız SQL Serverın ücretsiz versiyonunu kullanıyorsunuz yada profil name alanınız yoktur eklemeniz gerekecektir.

Msg 15281, Level 16, State 1, Procedure msdb.dbo.sp_send_dbmail, Line 0 [Batch Start Line 0]
SQL Server blocked access to procedure 'dbo.sp_send_dbmail' of component 'Database Mail XPs' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Database Mail XPs' by using sp_configure. For more information about enabling 'Database Mail XPs', search for 'Database Mail XPs' in SQL Server Books Online.





Hiç yorum yok:

Yorum Gönder