sending an email | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

sending an email

Hi, My name is Iming. I’m currently creating stored procedure to send an email. bellow is here is my code. this attached code bellow is working fine for only gmail users accounts, but not with others including hotmail, yahoo and etc (including my corporate email). Thank you all Regards, Iming
CREATE PROCEDURE sp_SMTPemail
–(
/*@From as nvarchar(50),
@To as nvarchar(50),
@Subject as nvarchar(255),
@Body as text */
–)
AS — Declare
DECLARE @message int
DECLARE @config int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255) EXEC @hr = sp_OACreate ‘CDO.Message’, @message OUT — create the message object
EXEC @hr = sp_OACreate ‘CDO.Configuration’, @config OUT — create the configuration object — Configuration Object
EXEC @hr = sp_OASetProperty @config, ‘Fields(cdoSendUsingMethod)’, ‘cdoSendUsingPort’ — Send the message using the network
EXEC @hr = sp_OASetProperty @config, ‘Fields(cdoSMTPServer)’, ‘sorry I can’t give my SMTP server, is the policy’ — SMTP Server
EXEC @hr = sp_OASetProperty @config, ‘Fields(cdoSMTPServerPort)’, 2 — Server SMTP Port
–EXEC @hr = sp_OASetProperty @config, ‘Fields(cdoSMTPAuthenticate)’, ‘cdoAnonymous’ — Anonymous SMTP Authenticate
EXEC sp_OAMethod @config, ‘Fields.Update’ — Message Object
EXEC @hr = sp_OASetProperty @message, ‘Configuration’, @config — set message.configuration = config
EXEC @hr = sp_OASetProperty @message, ‘To’, ‘[email protected]
EXEC @hr = sp_OASetProperty @message, ‘From’, ‘[email protected]
EXEC @hr = sp_OASetProperty @message, ‘Subject’, ‘IMING SUTANTO’
EXEC @hr = sp_OASetProperty @message, ‘TextBody’, ‘IMING SUTANTO TAN IMING SUTANTO TAN IMING SUTANTO TAN IMING SUTANTO TAN’
EXEC sp_OAMethod @message, ‘Send()’ — Destroys the objects
EXEC @hr = sp_OADestroy @message
EXEC @hr = sp_OADestroy @config — Errorhandler
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @message, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), [email protected], [email protected]
RETURN
END
GO
Iming
bit strage, check the mail server settings.
check whether your mails are go into the junk folder of those mails.
—————————————-
http://dineshasanka.blogspot.com/

]]>