Solved

Passing cookies when using CreateMHTMLBody

Posted on 2004-08-09
21
616 Views
Last Modified: 2012-05-05
 I'm trying to use the CDO CreateMHTMLBody function to send a web page by e-mail, but I'm having trouble sending cookies to the target page.  The contents of the page are determined by query variables, but I'm using cookies for forms-based authentication.

Here's my message-generating code:

      dim sCookies
      dim url
      dim objMessageConf
      dim objMessage

      sCookies = "foo=1;bar=2&bin=4;bas=3;"

      url = "http://site/page.asp?PRM=3665, 8926, 8926"

      set objMessageConf = CreateObject("CDO.Configuration")
      objMessageConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/httpcookies") = sCookies

      Set objMessage = CreateObject("CDO.Message")
      objMessage.Configuration = objMessageConf
      objMessage.Subject = "Test Message sent at " & now()
      objMessage.From = "myaddress@site.com"
      objMessage.To = "myaddress@site.com"

      objMessage.CreateMHTMLBody url

      objMessage.Send

Normally, the page being captured into e-mail would read these cookies with a line like this: (MGIS2004 is the name of my Application.)

      foo= Trim(Request.Cookies("MGIS2004")("foo"))

For debugging, I have this code to dump all cookies instead:

      public sub DumpVariables(coll)
            dim variable_name
            dim variable_value
      
            if len(coll) > 0 then
                  Response.Write "<p class=""DebugInfo"">"
                  for each variable_name in coll
                        variable_value=coll(variable_name)
                        response.write variable_name &" = "
                        response.write variable_value &" <br>" &chr(13)
                  next 'variable_name
                  Response.Write "</p>"
            end if
      end sub

      DumpVariables Request.Cookies
      Response.End

My resulting e-mail contains only:

      MGIS2004 =

Does anyone have any ideas why my cookies aren't coming across?


0
Comment
Question by:andrewcr
  • 11
  • 5
  • 3
  • +2
21 Comments
 
LVL 1

Author Comment

by:andrewcr
ID: 11764679
I guess this is harder than I thought.  I'll bump the points to 350....
0
 
LVL 1

Author Comment

by:andrewcr
ID: 11765661
Could someone reply just to let me know this if posted correctly, please?

Thanks,
  Andy
0
 
LVL 1

Author Comment

by:andrewcr
ID: 11772201
Is anybody out there?  500 Pts....
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11776062
You posted this correctly. I'm no expert at ASP so I can't help you (even though I wish I could ;), but that pointer question should point people to this post. Just be patient. If no one replies in a long time, you might want to check out the top 15 overall in ASP to see if they have email addresses and say they can be contacted.
0
 
LVL 11

Expert Comment

by:sciber_dude
ID: 11776114
Maybe you could test it by trying this...

response.write  "Cookies1:"  & DumpVariables(Request.Cookies)
response.write  "Cookies2:"  & DumpVariables(Request.Cookies(""MGIS2004""))

:) SD

0
 
LVL 11

Expert Comment

by:sciber_dude
ID: 11776135
I mean, Just try to paste these lines on the page being captured into e-mail and test it.

Dont test the email yet. Make sure you have the correct info on the page before you test the email aspect.

:) SD
0
 
LVL 11

Expert Comment

by:sciber_dude
ID: 11776222
oops! its a Sub!

DumpVariables Request.Cookies(""MGIS2004"")


should do the trick. If not, let us know

:) SD
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11776643
hi, can you try this and see if it works:

dim sCookies
     dim url
     dim objMessageConf
     dim objMessage

     sCookies = "foo=1;bar=2&bin=4;bas=3;"

     url = "http://site/page.asp?PRM=3665, 8926, 8926"

     Set objMessage = CreateObject("CDO.Message")
     objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/httpcookies") = sCookies
      objMessage.Subject = "Test Message sent at " & now()
     objMessage.From = "myaddress@site.com"
     objMessage.To = "myaddress@site.com"

     objMessage.CreateMHTMLBody url

     objMessage.Send
0
 
LVL 1

Author Comment

by:andrewcr
ID: 11776805
 I'm not getting any output from DumpVariables now.  I'll play with it a little more and get back to you in a few minutes...

  The page to be captured works fine with "normal" cookies.  It's part of an existing web application to which I'm trying to add an "e-mail this page" functionality.  It's only when I process the page through CreateMHTMLBody that I have the cookie problem.

  I couldn't find another way to process a page and capture the contents in a buffer, but aside from the cookies problem it seems to work, so I may as well send the mail....  8)
0
 
LVL 1

Author Comment

by:andrewcr
ID: 11777298
 OK, sciber_dude, I expanded the test code a little to show some more details, but still no luck.  Here's the test code I used:

      Response.Write "Request.Cookies:<br>"
      Response.Write "len=" & len(Request.Cookies) & "<br>"
       DumpVariables Request.Cookies
      Response.Write "Request.Cookies:(""MGIS2004"")<br>"
      Response.Write "len=" & len(Request.Cookies("MGIS2004")) & "<br>"
      DumpVariables Request.Cookies("MGIS2004")

And here's the resulting e-mail:

Request.Cookies:
len=0
Request.Cookies:("MGIS2004")
len=0

So, they really aren't coming through.


davidlars99, I'll try your code next...

Thanks guys -- I'll keep you posted.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:andrewcr
ID: 11777391
davidlars99, no luck.  The resulting e-mail body is identical:

Request.Cookies:
len=0
Request.Cookies:("MGIS2004")
len=0

0
 
LVL 5

Expert Comment

by:TMacT
ID: 11777415
Hello,

I noticed a couple of things. First, the line

url = "http://site/page.asp?PRM=3665, 8926, 8926"

has spaces in the URL. Do you know if these are being URL encoded or not ? They could be a source of problem. Second, when you call the function

objMessage.CreateMHTMLBody URL

does this not run on the IIS server ? So when the page requests the values from cookies, it would look for the cookies on the IIS server, not the clients cookies from their browser.

Just taking a stab ... I know what it is like to have an *unsolvable* problem.


... TMacT
0
 
LVL 1

Author Comment

by:andrewcr
ID: 11777658
 TMacT, that's a good point, but the query string part does appear to be working.  I added a few lines to the debug code and get this body:

Request.Cookies:
len=0
Request.Cookies:("MGIS2004")
len=0
Request.QueryString
len=54

PRM = 3665, 8926, 8926
time = 8/11/2004 3:44:00 PM


so the URL does seem to have come through OK.

  As far as the cookies: yes, the CreateMHTMLBody does run on the server, but the cookies I'm passing are server-side cookies.  Normally I can read them with an ASP statement like:

     foo= Trim(Request.Cookies("MGIS2004")("foo"))

  I'm assuming that the objMessage.Configuration takes server-side cookies, but that's right, isn't it?  As far as I know, ASP never reads/writes/sees client-side cookies.
0
 
LVL 13

Accepted Solution

by:
davidlars99 earned 500 total points
ID: 11777726
hi again,
 before you send it do this:  

objMessage.Configuration.Fields.Update
objMessage.send
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11777796
maybe you have to specify smtpserver and port? here's example, but I think update mothod should do it...

http://support.microsoft.com/?id=286431#appliesto

cheers!
 dave
0
 
LVL 1

Author Comment

by:andrewcr
ID: 11777970
 Hmm.  The server barfed with a 500 Internal Server error -- at least something different's happening.  8)

  Let me chew on this a little and I'll get back to you....
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11778344
that's because you dont have these configurations....

SMTP MailServer
          objMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = your_SMTP_MailServer
---------------------------------------------------------------------------------------------
SMTP Port
         objMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")  = your_smtp_port
---------------------------------------------------------------------------------------------
CDO Port
          objMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
----------------------------------------------------------------------------------------------
Timeout
          objMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
0
 
LVL 1

Author Comment

by:andrewcr
ID: 11778493
 Adding these doesn't change it.  It's failing on the CreateMHTMLBody call rather than the Send call.

  Unfortunately, I have to leave for the rest of the day.  Thanks very much for your help thus far -- I'll have another whack at it in the morning (US: Eastern Time).

Andy
0
 
LVL 1

Author Comment

by:andrewcr
ID: 11783620
 It works now.  8)

  The objMessage.Configuration.Fields.Update was the key.  The Internal Server Error turns out to be an unrelated bug in a DLL I use to generate the (captured) page.  And the SMTP settings seem to be optional -- if I don't use them it picks up the Info from the Front Page Extensions configuration.

  Thanks very much.  As they say in the Guinness commercials: "Brilliant!"

0
 
LVL 1

Author Comment

by:andrewcr
ID: 11783640
 One last note:  the Update must be done before the capture (CreateMHTMLBody) rather than before the Send.

  Thanks again.
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11783982
yep! and it MUST be done every time you call configuration..!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now