SQL Server Performance

Send mails with SQL Server

Discussion in 'Third Party Tools' started by realdrouin, Mar 3, 2005.

  1. realdrouin New Member

    I'm trying to send e-mails with SQL Server. I found a couple of example but none are working for me. I'm sure the examples are right, I'm just wondering if I have something to set up in SQL Server to "accept" sending e-mails?

    Right now, I'm running the examples and I receive no errors. It looks like the message was sent but I never received it.

    Real Drouin
  2. fhanlon New Member

    Are these mail programs using SMTP mail? If you are then all you need is a correctly configured SMTP server which is likely already set up. Sonfirm with your network admin. If you are talking about SQL Mail check out BOL for help configuring this. There's a fair bit to do.
  3. Madhivanan Moderator

    See where this works

    @From varchar(255),
    @To varchar(255),
    @Message varchar(8000),
    @Subject varchar(255))

    DECLARE @CDO int, @OLEResult int, @Out int

    --Create CDONTS.NewMail object
    EXECUTE @OLEResult = sp_OACreate 'CDONTS.NewMail', @CDO OUT
    IF @OLEResult <> 0 PRINT 'CDONTS.NewMail'

    EXECUTE @OLEResult = sp_OASetProperty @CDO, 'BodyFormat', 0
    EXECUTE @OLEResult = sp_OASetProperty @CDO, 'MailFormat', 0

    --Call Send method of the object
    execute @OLEResult = sp_OAMethod @CDO, 'Send', Null, @From, @To, @Subject, @Message, 1 --0 is low 1 is normal
    IF @OLEResult <> 0 PRINT 'Send'

    --Destroy CDO
    EXECUTE @OLEResult = sp_OADestroy @CDO

    return @OLEResult


    Failing to plan is Planning to fail
  4. satya Moderator

Share This Page