email component procedure

  • hi, i want to create a cdonts component in t-sql to include it in a storedprocedure. I have yet made with aspmail component, but i need to send mails throught another computer that hasnt license to use it.

    any help to send email without using aspmail? anyone know a free mail component?

    i post the code of my aspmail procedure, perhaps it is usefull to another people.

    exec @hr = sp_OACreate 'CDONTS.NewMail', @Mail OUT

    exec @hr=sp_OAsetproperty @Mail,'host','ipserver'

    exec @hr=sp_OASetProperty @Mail, 'fromName','fromname'

    exec @hr = sp_OASetProperty @Mail, 'Subject', 'subjectname'

    exec @hr=sp_OAsetproperty @mail,'from','fromaddress'

    exec @hr=sp_OAsetproperty @Mail,'ishtml','1'

    --EXEC @hr = sp_OAMethod @Mail, 'AddBcc', NULL, 'fromaddress'

    exec @hr=sp_OASetProperty @mail,'body',@cuerpomail

  • This was removed by the editor as SPAM

  • Unless you specifically need some feature of CDONTS (I am not quite sure exactly what you can and cannot do with it) I would recommend you to use Gert Draapers' extended procedure to send SMTP mail.

  • If you are using windows 2000 or 2003 this procedure which uses cdosys will work if you actually need to use cdonts because you're still on Nt you'll just need to tweak it a bit. I would add some security to this if I were you.

    SET QUOTED_IDENTIFIER OFF

    GO

    SET ANSI_NULLS ON

    GO

    ALTER PROCEDURE [dbo].[sp_send_cdosysmail]

    @From varchar(100) = "SQL@something.co.uk",

    @To varchar(100) ,

    @cc varchar(300)= " ",

    @Subject varchar(100)=" ",

    @Body varchar(4000) =" ",

    @Attachment varchar(255) = " "

    /*********************************************************************

    This stored procedure takes the parameters and sends an e-mail.

    Comments are added to the stored procedure where necessary.

    ***********************************************************************/

    AS

    Declare @iMsg int

    Declare @iBp int

    Declare @hr int

    Declare @source varchar(255)

    Declare @description varchar(500)

    Declare @output varchar(1000)

    --************* Create the CDO.Message Object ************************

    EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT

    --***************Configuring the Message Object ******************

    -- This is to configure a remote SMTP server.

    -- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_schema_configuration_sendusing.asp

    EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'

    -- This is to configure the Server Name or IP address.

    -- Replace MailServerName by the name or IP of your SMTP Server.

    EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', 'post.something.co.uk'

    -- Save the configurations to the message object.

    EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null

    -- Set the e-mail parameters.

    EXEC @hr = sp_OASetProperty @iMsg, 'To', @To

    EXEC @hr = sp_OASetProperty @iMsg, 'CC', @cc

    EXEC @hr = sp_OASetProperty @iMsg, 'From', @From

    EXEC @hr = sp_OASetProperty @iMsg, 'Subject', @Subject

    EXEC @hr = sp_OASetProperty @iMsg, 'TextBody', @Body

    EXEC @hr = sp_OAMethod @iMsg, 'AddAttachment', NULL, @Attachment

    EXEC @hr = sp_OAMethod @iMsg, 'Send', NULL

    -- Error handling.

    IF @hr 0

    select @hr

    BEGIN

    EXEC @hr = sp_OAGetErrorInfo NULL, @source OUT, @description OUT

    IF @hr = 0

    BEGIN

    SELECT @output = ' Source: ' + @source

    PRINT @output

    SELECT @output = ' Description: ' + @description

    PRINT @output

    END

    ELSE

    BEGIN

    PRINT ' sp_OAGetErrorInfo failed.'

    RETURN

    END

    END

    -- Clean up the objects created.

    EXEC @hr = sp_OADestroy @iMsg

    GO

    SET QUOTED_IDENTIFIER OFF

    GO

    SET ANSI_NULLS ON

    GO

    hth

    David

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply