CDO.Message parameter problem

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

    CDO.Message parameter problem

    I am trying to send mail from my ASP app using CDO, my
    problem is this.

    If I use a string in the .To field ie "me@myco.co m" the
    page works fine and the mail is sent, if I change the
    value to be the result of a recordset the page fails.

    I have used a response.write to check the recorset
    contains a valid email address, this appears to be fine.

    My code is listed below.

    Dim iMsg
    Dim iConf
    Dim Flds
    set iMsg = CreateObject("C DO.Message")
    set iConf = CreateObject("C DO.Configuratio n")
    Const cdoSendUsingPor t = 2
    Set Flds = iConf.Fields
    With Flds
    .Item
    ("http://schemas.microso ft.com/cdo/configuration/sendusing"
    ) = cdoSendUsingPor t
    .Item
    ("http://schemas.microso ft.com/cdo/configuration/smtpserver
    ") = "localhost"
    .Item
    ("http://schemas.microso ft.com/cdo/configuration/smtpconnec
    tiontimeout") = 10
    .Update
    End With

    'lookup users email address
    set myRecordSet = myUser.getUserE mailAddress(Req uest.form
    ("cboAssignTo") )
    emailto = myRecordSet(0)
    emailTitle = "Email Alert"
    emailFrom = "alert@iHotdesk .com"
    sBody = "Call Description: xxxxxx " & vbcr

    With iMsg
    Set .Configuration = iConf
    .To = emailto
    .From = emailFrom
    .Subject = emailTitle
    .TEXTBody = sBody
    .Send
    End With

    Any help greatfully appreciated.

    Thanks
  • Aaron Bertrand - MVP

    #2
    Re: CDO.Message parameter problem

    > value to be the result of a recordset the page fails.

    Could you be a little more specific?

    --
    Aaron Bertrand
    SQL Server MVP
    Please contact this domain's administrator as their DNS Made Easy services have expired.



    Comment

    • Tony B

      #3
      Re: CDO.Message parameter problem

      "Paul" <paul.sells@iho tdesk.com> wrote in message
      news:084301c3c5 71$30755cc0$a10 1280a@phx.gbl.. .[color=blue]
      > I am trying to send mail from my ASP app using CDO, my
      > problem is this.
      >
      > If I use a string in the .To field ie "me@myco.co m" the
      > page works fine and the mail is sent, if I change the
      > value to be the result of a recordset the page fails.
      >[/color]

      Are you sure that the smtp server you are using will relay mail to external
      addresses? If it's not configured to relay it may accept mail for a local
      domain but reject remote domains.

      Tony


      Comment

      • Paul Sells

        #4
        Re: CDO.Message parameter problem

        Aaron

        in the code I perfrom a lookup on the selected users email address
        before sending the mail as follows:
        ----------------------------------------
        'lookup users email address
        set myRecordSet = myUser.getUserE mailAddress(Req uest.form
        ("cboAssignTo") )
        emailto = myRecordSet(0)
        ------------------------------------------
        This returns the users email address, however if I set the .To field as
        follows:

        .To = emailto

        The page fails, however if I set

        .To = "anyone@abc.com "

        it works. The recordset is poplated with an email address, I have used
        response.write to verify the contents.

        The wierdest thing though is that I can use the contents as the from
        address (.From = emailto) without any problems.

        Regards,

        Paul






        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Aaron Bertrand - MVP

          #5
          Re: CDO.Message parameter problem

          You still haven't answered the question.
          [color=blue]
          > The page fails,[/color]

          I got that. What on earth does "fails" mean? Do you get an error
          message??? If so, don't you think it might be useful to include it?

          --
          Aaron Bertrand
          SQL Server MVP
          Please contact this domain's administrator as their DNS Made Easy services have expired.



          Comment

          • Mike D

            #6
            Re: CDO.Message parameter problem

            Is it possible there is an extra space coming from the db??

            Try checking the length of the string to make sure it is what you expect
            Len() and use Trim() to remove any if there are extra.

            Long shot I know.

            Mike


            "Paul" <anonymous@disc ussions.microso ft.com> wrote in message
            news:0c1b01c3c5 80$35e6f4c0$a60 1280a@phx.gbl.. .[color=blue]
            >
            > Tony,
            >
            > the server is sending mail without any problems, if I set
            > the contents of the .TO field as follows
            > .TO = "john.smith@abc .com"
            > it works fine yet if I use
            > .To = emailto it does not work even though emailto is
            > pouplated with a valid email address.
            >
            > I have been doing some other testing and have also found
            > it works ok for the .From field (.From = emailto) but not
            > the .To field.
            >
            >
            >
            >
            >
            >
            >
            >[color=green]
            > >-----Original Message-----
            > >"Paul" <paul.sells@iho tdesk.com> wrote in message
            > >news:084301c3c 571$30755cc0$a1 01280a@phx.gbl. ..[color=darkred]
            > >> I am trying to send mail from my ASP app using CDO, my
            > >> problem is this.
            > >>
            > >> If I use a string in the .To field ie "me@myco.co m" the
            > >> page works fine and the mail is sent, if I change the
            > >> value to be the result of a recordset the page fails.
            > >>[/color]
            > >
            > >Are you sure that the smtp server you are using will[/color]
            > relay mail to external[color=green]
            > >addresses? If it's not configured to relay it may accept[/color]
            > mail for a local[color=green]
            > >domain but reject remote domains.
            > >
            > >Tony
            > >
            > >
            > >.
            > >[/color][/color]


            Comment

            • paul

              #7
              Re: CDO.Message parameter problem

              Thanks Mike,

              tried len() and it checks out ok, I've also tried removing leading and
              trailing spaces and also tried using cstr() but still no joy.


              P






              *** Sent via Developersdex http://www.developersdex.com ***
              Don't just participate in USENET...get rewarded for it!

              Comment

              • Aaron Bertrand - MVP

                #8
                Re: CDO.Message parameter problem

                > still no joy.

                Are we on a mission to be as vague as possible?

                What do the statements "fails" and "no joy" mean???

                --
                Aaron Bertrand
                SQL Server MVP
                Please contact this domain's administrator as their DNS Made Easy services have expired.



                Comment

                • paul

                  #9
                  Re: CDO.Message parameter problem

                  Aaron,


                  when the page is working it posts back to itself (i.e. when I set the
                  .TO = "anyone@abc.com ") when it fails all I receive is a HTTP 500 -
                  Internal server error.

                  I've chedked the event logs and IIS logs but can;t find anything, I've
                  also switched debugging on and set the 'Send details ASP error messages
                  to client' option to ON in IIS but still can;t get any meaningfull
                  errors.

                  P



                  *** Sent via Developersdex http://www.developersdex.com ***
                  Don't just participate in USENET...get rewarded for it!

                  Comment

                  • Aaron Bertrand - MVP

                    #10
                    Re: CDO.Message parameter problem

                    > when it fails all I receive is a HTTP 500 - Internal server error.

                    Ah, a light bulb must have gone somewhere! Hooray! Do you see why it's
                    difficult to proceed when the only description you give is, "it's broken"?

                    Now, let's find out what the real error is. http://www.aspfaq.com/2109

                    --
                    Aaron Bertrand
                    SQL Server MVP
                    Please contact this domain's administrator as their DNS Made Easy services have expired.



                    Comment

                    • TomB

                      #11
                      Re: CDO.Message parameter problem

                      How about doing a ....
                      Response.Write emailto & "<BR>"
                      Response.Flush

                      Right after you set that value, I'll bet that it's an invalid email address.

                      "Paul" <paul.sells@iho tdesk.com> wrote in message
                      news:084301c3c5 71$30755cc0$a10 1280a@phx.gbl.. .[color=blue]
                      > I am trying to send mail from my ASP app using CDO, my
                      > problem is this.
                      >
                      > If I use a string in the .To field ie "me@myco.co m" the
                      > page works fine and the mail is sent, if I change the
                      > value to be the result of a recordset the page fails.
                      >
                      > I have used a response.write to check the recorset
                      > contains a valid email address, this appears to be fine.
                      >
                      > My code is listed below.
                      >
                      > Dim iMsg
                      > Dim iConf
                      > Dim Flds
                      > set iMsg = CreateObject("C DO.Message")
                      > set iConf = CreateObject("C DO.Configuratio n")
                      > Const cdoSendUsingPor t = 2
                      > Set Flds = iConf.Fields
                      > With Flds
                      > .Item
                      > ("http://schemas.microso ft.com/cdo/configuration/sendusing"
                      > ) = cdoSendUsingPor t
                      > .Item
                      > ("http://schemas.microso ft.com/cdo/configuration/smtpserver
                      > ") = "localhost"
                      > .Item
                      > ("http://schemas.microso ft.com/cdo/configuration/smtpconnec
                      > tiontimeout") = 10
                      > .Update
                      > End With
                      >
                      > 'lookup users email address
                      > set myRecordSet = myUser.getUserE mailAddress(Req uest.form
                      > ("cboAssignTo") )
                      > emailto = myRecordSet(0)
                      > emailTitle = "Email Alert"
                      > emailFrom = "alert@iHotdesk .com"
                      > sBody = "Call Description: xxxxxx " & vbcr
                      >
                      > With iMsg
                      > Set .Configuration = iConf
                      > .To = emailto
                      > .From = emailFrom
                      > .Subject = emailTitle
                      > .TEXTBody = sBody
                      > .Send
                      > End With
                      >
                      > Any help greatfully appreciated.
                      >
                      > Thanks[/color]


                      Comment

                      • paul

                        #12
                        Re: CDO.Message parameter problem


                        Aaron,


                        when I submit the page with the TO field populated with the contents of
                        my recordset I get a HTTP 500 error, when I submit the page and
                        substitute the recordset contents for "me@atmycompany .com" the page
                        submits and an email is sent to me. I can;t be more specific than that.

                        I have tried populating the .FROM field with the contents of the
                        recordset and this works (I receive an email with the from field set to
                        the correct address). What I can;t work out is why I can't use the
                        value from my recordset in the TO field yet I can use it in the FROM
                        field.

                        I may sound like I'm being vague but IIS is not helping matters by only
                        giving me a HTTP 500 error.

                        P

                        *** Sent via Developersdex http://www.developersdex.com ***
                        Don't just participate in USENET...get rewarded for it!

                        Comment

                        • Aaron Bertrand - MVP

                          #13
                          Re: CDO.Message parameter problem

                          > I may sound like I'm being vague but IIS is not helping matters by only[color=blue]
                          > giving me a HTTP 500 error.[/color]

                          That is your BROWSER causing that, not IIS. See my other reply.

                          --
                          Aaron Bertrand
                          SQL Server MVP
                          Please contact this domain's administrator as their DNS Made Easy services have expired.



                          Comment

                          Working...