Solved

Passing cookies when using CreateMHTMLBody

Posted on 2004-08-09
21
636 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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