SQL MAIL through SMTP

SQL MAIL through SMTP

 

  

Hi guys,



I have a problem when I send mails through SQL SERVER using SMTP. It
doesn't generate any errors but the mail is not going, I don't know why

Please help me in the same, am I missing something important

The following is the code





create Procedure dbo.SP_SMTPMail



@SenderName varchar(100),

@SenderAddress varchar(100),

@RecipientName varchar(100),

@RecipientAddress varchar(100),

@Subject varchar(200),

@Body varchar(8000),

@MailServer varchar(100) = 'localhost'

AS



SET nocount on



declare @oMail int --Object reference

declare @resultcode int



EXEC @resultcode = sp_OACreate 'SMTPsvg.Mailer', @oMail OUT
---------- and I replace this 'SMTPsvg.Mailer' with the domain name
found in IIS



if @resultcode = 0

BEGIN

EXEC @resultcode = sp_OASetProperty @oMail,
'RemoteHost', @mailserver

EXEC @resultcode = sp_OASetProperty @oMail,
'FromName', @SenderName

EXEC @resultcode = sp_OASetProperty @oMail,
'FromAddress', @SenderAddress



EXEC @resultcode = sp_OAMethod @oMail,
'AddRecipient', NULL, @RecipientName, @RecipientAddress



EXEC @resultcode = sp_OASetProperty @oMail,
'Subject', @Subject

EXEC @resultcode = sp_OASetProperty @oMail,
'BodyText', @Body





EXEC @resultcode = sp_OAMethod @oMail,
'SendMail', NULL



EXEC sp_OADestroy @oMail

END





SET nocount off







------------------- EXECUTING USING



exec sp_SMTPMail @SenderName='abc', @SenderAddress='[Email address protected]

@RecipientName = 'uwv', @RecipientAddress = '[Email address protected]

@Subject='SQL TEST MAIL', @body='Hello, this is a test email from SQL
Server. Please Ignore'







Thanks in advance



Vini


MS Sql Server LazyDBA home page