Help sending email

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • B

    Help sending email

    My code below works fine when run from my pc (changed all the values for
    obvious reasons). The code is placed inside a DTS task via VBS scripting.
    But when I try to run directly from the server where sqlserver is installed,
    the script fails.

    I have SMTP running, but there is no outlook installed.

    Can someone please advise what I am missing.
    Thanks
    Bob


    Set objEmail = CreateObject("C DO.Message")

    objEmail.From = "send@test. com"
    objEmail.To = "receive@test.c om"
    objEmail.Subjec t = "TEST SUBJECT"
    objEmail.AddAtt achment "\\server\test. csv"
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/sendusing") = 2
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/smtpserver") = "SERVER_NAM E"
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/smtpauthenticat e") = 1
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/sendusername") = "username"
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/sendpassword") = "userpwd"
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/smtpserverport" ) = 25
    objEmail.Config uration.Fields. Update
    objEmail.Send

    set objEmail = nothing


  • DickChristoph

    #2
    Re: Help sending email

    Hi B

    One thing you might try is change
    [color=blue]
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/sendusing") = 2[/color]
    to[color=blue]
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/sendusing") = "2"[/color]

    quotes around the 2.

    I spent several hours a week ago trying the very same thing and that made
    all the difference.

    Also is \\server\test.c sv accessible from the server you are running this
    on?

    Here is the full text of the DTS Package I wrote. Note that I don't think
    all the fields you included are necessary.

    '************** *************** *************** *************** ***********
    ' Visual Basic ActiveX Script
    '************** *************** *************** *************** *************

    Function Main()
    email_alert "dchristo@yahoo .com", "George_Bush@wh itehouse.gov"," Test
    Subject", "Test Body"
    Main = DTSTaskExecResu lt_Success
    End Function

    Sub email_alert(str To, strFrom, strSubject, strBody)
    Dim iConf 'As CDO.Configurati on
    Dim imsg 'As CDO.Message
    Dim flds

    Set imsg = CreateObject("C DO.Message")
    Set iConf = CreateObject("C DO.Configuratio n")

    Set flds = iConf.Fields

    'The http://schemas.microsoft.com/cdo/configuration/ namespace defines
    the majority of fields used to set configurations for various CDO objects.
    We set and update the following three fields (SendUsing, SMTP_SERVER, and
    TimeOut) of the Configuration object:

    With flds
    .Item("http://schemas.microso ft.com/cdo/configuration/sendusing") =
    "2"
    .Item("http://schemas.microso ft.com/cdo/configuration/smtpserver") =
    "smtp-server.mn.rr.co m"
    .Item("http://schemas.microso ft.com/cdo/configuration/smtpconnectiont imeout")
    = 10
    .Update
    End With

    Set imsg.Configurat ion = iConf
    imsg.To = strTo
    imsg.From = strFrom
    imsg.Subject = strSubject
    imsg.TextBody = strBody
    imsg.AddAttachm ent "c:\log\myfile. txt"
    imsg.Send
    End Sub
    --
    -Dick Christoph

    "B" <no_spam@no_spa m.com> wrote in message
    news:KsydnTnYtf FV2wbZnZ2dnUVZ_ uqdnZ2d@rcn.net ...[color=blue]
    > My code below works fine when run from my pc (changed all the values for
    > obvious reasons). The code is placed inside a DTS task via VBS scripting.
    > But when I try to run directly from the server where sqlserver is
    > installed,
    > the script fails.
    >
    > I have SMTP running, but there is no outlook installed.
    >
    > Can someone please advise what I am missing.
    > Thanks
    > Bob
    >
    >
    > Set objEmail = CreateObject("C DO.Message")
    >
    > objEmail.From = "send@test. com"
    > objEmail.To = "receive@test.c om"
    > objEmail.Subjec t = "TEST SUBJECT"
    > objEmail.AddAtt achment "\\server\test. csv"
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/sendusing") = 2
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/smtpserver") = "SERVER_NAM E"
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/smtpauthenticat e") = 1
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/sendusername") = "username"
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/sendpassword") = "userpwd"
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/smtpserverport" ) = 25
    > objEmail.Config uration.Fields. Update
    > objEmail.Send
    >
    > set objEmail = nothing
    >
    >[/color]


    Comment

    • B

      #3
      Re: Help sending email - additional question

      Follow-up to my original post below.

      Is it possible for the "objEmail.T o" to lookup the values from a sqlserver
      table?

      At the moment, I type the email address separated by a semi-colon.

      TIA~


      "B" <no_spam@no_spa m.com> wrote in message
      news:KsydnTnYtf FV2wbZnZ2dnUVZ_ uqdnZ2d@rcn.net ...[color=blue]
      > My code below works fine when run from my pc (changed all the values for
      > obvious reasons). The code is placed inside a DTS task via VBS scripting.
      > But when I try to run directly from the server where sqlserver is[/color]
      installed,[color=blue]
      > the script fails.
      >
      > I have SMTP running, but there is no outlook installed.
      >
      > Can someone please advise what I am missing.
      > Thanks
      > Bob
      >
      >
      > Set objEmail = CreateObject("C DO.Message")
      >
      > objEmail.From = "send@test. com"
      > objEmail.To = "receive@test.c om"
      > objEmail.Subjec t = "TEST SUBJECT"
      > objEmail.AddAtt achment "\\server\test. csv"
      >[/color]
      objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=blue]
      > ration/sendusing") = 2
      >[/color]
      objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=blue]
      > ration/smtpserver") = "SERVER_NAM E"
      >[/color]
      objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=blue]
      > ration/smtpauthenticat e") = 1
      >[/color]
      objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=blue]
      > ration/sendusername") = "username"
      >[/color]
      objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=blue]
      > ration/sendpassword") = "userpwd"
      >[/color]
      objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=blue]
      > ration/smtpserverport" ) = 25
      > objEmail.Config uration.Fields. Update
      > objEmail.Send
      >
      > set objEmail = nothing
      >
      >[/color]


      Comment

      • DickChristoph

        #4
        Re: Help sending email - additional question

        Hi B,

        Well not directly but you could create an ADODB Command, Connection and
        Recordset and use the command to return you a recordset from the Database
        that would have 1 or many email addresses that you could concatenate
        together and stick in the objEmail.To field.

        --
        -Dick Christoph
        "B" <no_spam@no_spa m.com> wrote in message
        news:c4mdnfssT4 5ImT7ZnZ2dnUVZ_ r-dnZ2d@rcn.net.. .[color=blue]
        > Follow-up to my original post below.
        >
        > Is it possible for the "objEmail.T o" to lookup the values from a sqlserver
        > table?
        >
        > At the moment, I type the email address separated by a semi-colon.
        >
        > TIA~
        >
        >
        > "B" <no_spam@no_spa m.com> wrote in message
        > news:KsydnTnYtf FV2wbZnZ2dnUVZ_ uqdnZ2d@rcn.net ...[color=green]
        >> My code below works fine when run from my pc (changed all the values for
        >> obvious reasons). The code is placed inside a DTS task via VBS
        >> scripting.
        >> But when I try to run directly from the server where sqlserver is[/color]
        > installed,[color=green]
        >> the script fails.
        >>
        >> I have SMTP running, but there is no outlook installed.
        >>
        >> Can someone please advise what I am missing.
        >> Thanks
        >> Bob
        >>
        >>
        >> Set objEmail = CreateObject("C DO.Message")
        >>
        >> objEmail.From = "send@test. com"
        >> objEmail.To = "receive@test.c om"
        >> objEmail.Subjec t = "TEST SUBJECT"
        >> objEmail.AddAtt achment "\\server\test. csv"
        >>[/color]
        > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=green]
        >> ration/sendusing") = 2
        >>[/color]
        > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=green]
        >> ration/smtpserver") = "SERVER_NAM E"
        >>[/color]
        > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=green]
        >> ration/smtpauthenticat e") = 1
        >>[/color]
        > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=green]
        >> ration/sendusername") = "username"
        >>[/color]
        > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=green]
        >> ration/sendpassword") = "userpwd"
        >>[/color]
        > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu[color=green]
        >> ration/smtpserverport" ) = 25
        >> objEmail.Config uration.Fields. Update
        >> objEmail.Send
        >>
        >> set objEmail = nothing
        >>
        >>[/color]
        >
        >[/color]


        Comment

        Working...