Sql Server mail göndermek

Bu yazımızda sql database’den otomatik mail gönderimini sağlayacak prosedüre’ü yazacağız. 
 
CRATE PROCEDURE [dbo].[PROC_MailGonder]
AS
SET NOCOUNT ON
declare @sonuc nvarchar(max)
declare @table nvarchar(max)
declare @baslik nvarchar(max)
declare @message nvarchar(max)
declare @tarih datetime
declare @CurrencyName nvarchar(250)
declare @ForexBuying nvarchar (10)
declare @ForexSelling nvarchar(10)

set @tarih=GETDATE()
set @sonuc='

Sayın Yetkili,

'+'Tcmb döviz kurları aşağıdaki gibidir.


'
set @baslik= 'TCMB döviz kurları'

DECLARE CursDoviz_kurlari CURSOR FOR
select top 10 CurrencyName, ForexBuying, ForexSelling from DOVIZKURLARI

OPEN CursDoviz_kurlari
FETCH NEXT FROM CursDoviz_kurlari into @CurrencyName, @ForexBuying, @ForexSelling
WHILE @@FETCH_STATUS = 0 BEGIN

set @table=''

set @sonuc=@sonuc+@table

FETCH NEXT FROM CursDoviz_kurlari into @CurrencyName, @ForexBuying, @ForexSelling
END
CLOSE CursDoviz_kurlari
DEALLOCATE CursDoviz_kurlari

set @message=(select @sonuc + '
currency nameTarihforex buyingforex selling
'+isnull(@CurrencyName,'')+''+isnull(convert(nvarchar(10),@tarih,104),'')+''+isnull(cast(@ForexBuying as nvarchar(10)),'')+''+isnull(@ForexSelling,'')+'

Bilginize,

şirket logosu


Bu e-posta mesajı kişiye özel olup, gizli bilgiler içeriyor olabilir.

Eğer bu e-posta mesajı size yanlışlıkla ulaşmışsa, e-posta mesajını kullanıcıya hemen geri gönderiniz ve mesaj kutunuzdan siliniz.
Bu e-posta mesajı, hiç bir şekilde, herhangi bir amaç için çoğaltılamaz, yayınlanamaz ve para karşılığı satılamaz.
Yollayıcı, bu e-posta mesajının - virüs koruma sistemleri ile kontrol ediliyor olsa bile - virüs içermediğini garanti etmez ve meydana gelebilecek zararlardan doğacak hiçbir sorumluluğu kabul etmez.



The information contained in this message is confidential, intended solely for the use of the individual or entity to whom it is addressed and may be protected by professional secrecy.
You should not copy, disclose or distribute this information for any purpose. If you are not the intended recipient of this message or you receive this mail in error, you should refrain from making any use of the contents and from opening any attachment.
In that case, please notify the sender immediately and return the message to the sender, then, delete and destroy all copies. This e-mail message has been swept by anti-virus systems for the presence of computer viruses.
In doing so, however, we cannot warrant that virus or other forms of data corruption may not be present and we do not take any responsibility in any occurrence.



')

EXEC [msdb].[dbo].[sp_send_dbmail] @profile_name ='MAIL_GONDER', @recipients = 'puzzleistt@gmail.com', @body = @message, @subject = @baslik,@body_format='HTML'

Yorum bırakın