Sending email with CDO from Access

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

    #1

    Sending email with CDO from Access

    I'm trying to send an email from an Access procedure using CDO. I've
    been able to do it successfully with three different sending email
    addresses, but not with the email address I actually need to use in
    production. In that case I get a message saying "The transport failed
    to connect to the server." I've tried several different ports. Anybody
    have any idea what the problem might be? My code is below.

    -----------------------------------------------------------------------------------------
    Public Sub SendEmail()
    Dim imsg As Message
    Dim iconf As Object
    Dim flds As Object
    Dim schema As String

    Set imsg = CreateObject("C DO.Message")
    Set iconf = CreateObject("C DO.Configuratio n")
    Set flds = iconf.Fields

    ' send one copy with SMTP server (with autentication)
    schema = "http://schemas.microso ft.com/cdo/configuration/"
    flds.Item(schem a & "sendusing" ) = cdoSendUsingPor t
    flds.Item(schem a & "smtpserver ") = "mail2.mycompan y.com"
    flds.Item(schem a & "smtpserverport ") = 25
    flds.Item(schem a & "smtpauthentica te") = cdoBasic
    flds.Item(schem a & "senduserna me") = "address@mycomp any.com"
    flds.Item(schem a & "sendpasswo rd") = "123abc456"
    flds.Item(schem a & "smtpusessl ") = 1
    flds.Update

    With imsg
    ..To = "evancater@juno .com"
    ..From = "Sender <address@mycomp any.com>"
    ..Subject = "Test send"
    ..HTMLBody = "Test"
    ..Sender = "Sender"
    ..Organization = "My Company"
    '.ReplyTo = "address@mycomp any.com"
    Set .Configuration = iconf
    ..Send
    End With

    Set iconf = Nothing
    Set imsg = Nothing
    Set flds = Nothing
    End Sub
    -----------------------------------------------------------------------------------------
  • lyle fairfield

    #2
    Re: Sending email with CDO from Access

    THis usually happens to me when I don't give the SMTP server the
    information it needs in the form it needs.

    BTW, your code uuse both late binding and early binding. That probably
    has nothing to do with your problem, it's just très ugly.


    On Aug 26, 1:14 pm, evenlater <evanca...@gmai l.comwrote:
    I'm trying to send an email from an Access procedure using CDO. I've
    been able to do it successfully with three different sending email
    addresses, but not with the email address I actually need to use in
    production. In that case I get a message saying "The transport failed
    to connect to the server." I've tried several different ports. Anybody
    have any idea what the problem might be? My code is below.
    >
    ---------------------------------------------------------------------------­--------------
    Public Sub SendEmail()
    Dim imsg As Message
    Dim iconf As Object
    Dim flds As Object
    Dim schema As String
    >
    Set imsg = CreateObject("C DO.Message")
    Set iconf = CreateObject("C DO.Configuratio n")
    Set flds = iconf.Fields
    >
    ' send one copy with SMTP server (with autentication)
    schema = "http://schemas.microso ft.com/cdo/configuration/"
    flds.Item(schem a & "sendusing" ) = cdoSendUsingPor t
    flds.Item(schem a & "smtpserver ") = "mail2.mycompan y.com"
    flds.Item(schem a & "smtpserverport ") = 25
    flds.Item(schem a & "smtpauthentica te") = cdoBasic
    flds.Item(schem a & "senduserna me") = "addr...@mycomp any.com"
    flds.Item(schem a & "sendpasswo rd") = "123abc456"
    flds.Item(schem a & "smtpusessl ") = 1
    flds.Update
    >
    With imsg
    .To = "evanca...@juno .com"
    .From = "Sender <addr...@mycomp any.com>"
    .Subject = "Test send"
    .HTMLBody = "Test"
    .Sender = "Sender"
    .Organization = "My Company"
    '.ReplyTo = "addr...@mycomp any.com"
    Set .Configuration = iconf
    .Send
    End With
    >
    Set iconf = Nothing
    Set imsg = Nothing
    Set flds = Nothing
    End Sub
    ---------------------------------------------------------------------------­--------------

    Comment

    • evenlater

      #3
      Re: Sending email with CDO from Access

      Thanks. I'm new at this... how would I change it to use either late or
      early binding?

      On Aug 26, 2:09 pm, lyle fairfield <lyle.fairfi... @gmail.comwrote :
      THis usually happens to me when I don't give the SMTP server the
      information it needs in the form it needs.
      >
      BTW, your code uuse both late binding and early binding. That probably
      has nothing to do with your problem, it's just très ugly.

      Comment

      • Stuart McCall

        #4
        Re: Sending email with CDO from Access

        "evenlater" <evancater@gmai l.comwrote in message
        news:d67a5744-a594-4dcd-b3e0-7051c415a26a@v3 9g2000pro.googl egroups.com...
        I'm trying to send an email from an Access procedure using CDO. I've
        been able to do it successfully with three different sending email
        addresses, but not with the email address I actually need to use in
        production. In that case I get a message saying "The transport failed
        to connect to the server." I've tried several different ports. Anybody
        have any idea what the problem might be? My code is below.
        >
        -----------------------------------------------------------------------------------------
        Public Sub SendEmail()
        Dim imsg As Message
        Dim iconf As Object
        Dim flds As Object
        Dim schema As String
        >
        Set imsg = CreateObject("C DO.Message")
        Set iconf = CreateObject("C DO.Configuratio n")
        Set flds = iconf.Fields
        >
        ' send one copy with SMTP server (with autentication)
        schema = "http://schemas.microso ft.com/cdo/configuration/"
        flds.Item(schem a & "sendusing" ) = cdoSendUsingPor t
        flds.Item(schem a & "smtpserver ") = "mail2.mycompan y.com"
        flds.Item(schem a & "smtpserverport ") = 25
        flds.Item(schem a & "smtpauthentica te") = cdoBasic
        flds.Item(schem a & "senduserna me") = "address@mycomp any.com"
        flds.Item(schem a & "sendpasswo rd") = "123abc456"
        flds.Item(schem a & "smtpusessl ") = 1
        flds.Update
        >
        With imsg
        .To = "evancater@juno .com"
        .From = "Sender <address@mycomp any.com>"
        .Subject = "Test send"
        .HTMLBody = "Test"
        .Sender = "Sender"
        .Organization = "My Company"
        '.ReplyTo = "address@mycomp any.com"
        Set .Configuration = iconf
        .Send
        End With
        >
        Set iconf = Nothing
        Set imsg = Nothing
        Set flds = Nothing
        End Sub
        -----------------------------------------------------------------------------------------
        Because you're using late binding (ie CreateObject), and have no reference
        set to the CDO library, the following constants are not defined:

        Const cdoSendUsingPor t = 2
        Const cdoBasic = 1

        Insert those 2 lines at the top of your procedure and give that a try.


        Comment

        • lyle fairfield

          #5
          Re: Sending email with CDO from Access

          At http://www.ffdba.com/downloads/Send_E-Mail_With_CDO.htm
          there are two examples. One is all early-binding and the other is all
          late.

          On Aug 26, 5:05 pm, evenlater <evanca...@gmai l.comwrote:
          Thanks. I'm new at this... how would I change it to use either late or
          early binding?
          >
          On Aug 26, 2:09 pm, lyle fairfield <lyle.fairfi... @gmail.comwrote :
          >
          >
          >
          THis usually happens to me when I don't give the SMTP server the
          information it needs in the form it needs.
          >
          BTW, your code uuse both late binding and early binding. That probably
          has nothing to do with your problem, it's just très ugly.

          Comment

          • Tom van Stiphout

            #6
            Re: Sending email with CDO from Access

            On Tue, 26 Aug 2008 10:14:18 -0700 (PDT), evenlater
            <evancater@gmai l.comwrote:

            Try this:
            flds.Item(schem a & "senduserna me") = "address"
            Just yesterday that helped us with some ISP.

            Of course the u/pw is only needed if the SMTP server requires it.

            -Tom.
            Microsoft Access MVP


            >I'm trying to send an email from an Access procedure using CDO. I've
            >been able to do it successfully with three different sending email
            >addresses, but not with the email address I actually need to use in
            >production. In that case I get a message saying "The transport failed
            >to connect to the server." I've tried several different ports. Anybody
            >have any idea what the problem might be? My code is below.
            >
            >-----------------------------------------------------------------------------------------
            >Public Sub SendEmail()
            >Dim imsg As Message
            >Dim iconf As Object
            >Dim flds As Object
            >Dim schema As String
            >
            >Set imsg = CreateObject("C DO.Message")
            >Set iconf = CreateObject("C DO.Configuratio n")
            >Set flds = iconf.Fields
            >
            >' send one copy with SMTP server (with autentication)
            >schema = "http://schemas.microso ft.com/cdo/configuration/"
            >flds.Item(sche ma & "sendusing" ) = cdoSendUsingPor t
            >flds.Item(sche ma & "smtpserver ") = "mail2.mycompan y.com"
            >flds.Item(sche ma & "smtpserverport ") = 25
            >flds.Item(sche ma & "smtpauthentica te") = cdoBasic
            >flds.Item(sche ma & "senduserna me") = "address@mycomp any.com"
            >flds.Item(sche ma & "sendpasswo rd") = "123abc456"
            >flds.Item(sche ma & "smtpusessl ") = 1
            >flds.Update
            >
            >With imsg
            >.To = "evancater@juno .com"
            >.From = "Sender <address@mycomp any.com>"
            >.Subject = "Test send"
            >.HTMLBody = "Test"
            >.Sender = "Sender"
            >.Organizatio n = "My Company"
            >'.ReplyTo = "address@mycomp any.com"
            >Set .Configuration = iconf
            >.Send
            >End With
            >
            >Set iconf = Nothing
            >Set imsg = Nothing
            >Set flds = Nothing
            >End Sub
            >-----------------------------------------------------------------------------------------

            Comment

            • Tony Toews [MVP]

              #7
              Re: Sending email with CDO from Access

              evenlater <evancater@gmai l.comwrote:
              >Thanks. I'm new at this... how would I change it to use either late or
              >early binding?
              I'd suggest late binding once you've got the code debugged.

              Late binding means you can safely remove the reference and only have an error when
              the app executes lines of code in question. Rather than erroring out while starting
              up the app and not allowing the users in the app at all. Or when hitting a mid, left
              or trim function call.

              This also is very useful when you don't know version of the external application
              will reside on the target system. Or if your organization is in the middle of moving
              from one version to another.

              For more information including additional text and some detailed links see the "Late
              Binding in Microsoft Access" page at http://www.granite.ab.ca/access/latebinding.htm

              Tony
              --
              Tony Toews, Microsoft Access MVP
              Please respond only in the newsgroups so that others can
              read the entire thread of messages.
              Microsoft Access Links, Hints, Tips & Accounting Systems at

              Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/

              Comment

              Working...