RE: SQL MAIL through SMTP

RE: SQL MAIL through SMTP

 

  

Is there a particular reason you are not using the xp_sendmail
procedure?

-----Original Message-----
From: Vinoth R
[mailto:mssqldba-ezmlmshield-x5547818.[Email address protected]
Sent: 29 June 2006 09:49
To: LazyDBA Discussion
Subject: 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



---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY Website :
http://www.LazyDBA.com To unsubscribe:
http://www.lazydba.com/unsubscribe.html


This email and any files transmitted within it are private and confidential.
If you are not the intended recipient, this email and any attachments within it have been transmitted to you in error.
You are prohibited from using, copying, distributing or otherwise using the information contained within this email.
Nothing in this email message amounts to a contractual or legal commitment on the part of Optilan unless confirmed by a communication signed on behalf of the company.
Any email cannot be guaranteed to be secure, error free or free from viruses. Although every possible care is taken by Optilan, Optilan does not accept any liability whatsoever for any loss or damage which may be caused as a result of the transmission of this message by email.


MS Sql Server LazyDBA home page