Solved

How do I avoid embedding images in CDO.message?

Posted on 2007-04-05
15
638 Views
Last Modified: 2009-12-16
Hi,

This might be a non-question on my part, but I have a little application I use for my news website that generates a newsletter email to let my readers know when the site has been updated (it's an anime review site).
I have about 200 subscribers, who all subscribe through the site, and they can unsubscribe at any time, so it's not a spam-o-matic by any means. (I send about 1 a month).

I'm sending the email through CDO.messages as I understand that's the most efficient way, using the following code:

Set ObjMail = CreateObject("CDO.message")
  ObjMail.FROM = rsUser("userEMAIL")
  ObjMail.TO = rsRecipient("Email")
  ObjMail.Subject = rsCampaign("CampaignName")
  ObjMail.CreateMHTMLBody ""&Location&"/campaign.asp?intID="&request.form("intID")&"&Campaign="&rsCampaign("ID")&"&rID="&rsRecipient("ID")&""
  ObjMail.Send

I think it's embedding the images, because when I view the source I get this:

<img src="cid:000501c77773$0ab54146$_CDOSYS2.0">

So my question is twofold:

Does this mean the image is embedded and If so, is that placing more strain on my server when sending the email?
How can I change the code to ensure that images aren't embedded?

Ideally I want the images to point to my server, so that it will send as efficiently as possible, i.e. without images. I'm hosting on Windows Server Standard 2003.

Any light you guys can shed would be very much appreciated!
0
Comment
Question by:Forjey
  • 6
  • 5
  • 4
15 Comments
 
LVL 25

Expert Comment

by:kevp75
ID: 18857455
fisrt off...some clarification please....first you say you don't want the image, then you say you do?

secondly, your code looks right...it won't put any extra strain on the server.

as for how to get rid of it...well...if you aren't putting it there, it shouldn't be there, might I suggest using a different email component?  Something like ASPEmail, or jMail...
0
 

Author Comment

by:Forjey
ID: 18857530
Okay, for clarification, I want to display an image in the html email  (banner graphic plus one extra related to the topic) but I don't really want to send the image with the email, otherwise, a 20k file linking to a 100k image becomes a 120k email if it's all mailed together, rather than a 20k email with a hard coded link to the image. (reading it back I can see how it's a little confusing, sorry).

The page that the objMail.Create line refers to, campaign.asp, uses hard coded links to the images.

I wondered if using objMail.Create and sending a page caused the server to wrap it all up send everything together - I just want it to send the code as a html page.

I hope that clarifies things, thank you for responding.
0
 
LVL 25

Assisted Solution

by:kevp75
kevp75 earned 100 total points
ID: 18858023
you can send it as an HTML page, the main thing with the images though is that you will want to put the full address to the image.
so

it would basically need to be:
<img src="http://yoursite.com/images/image.jpg">

you really just need to make sure that what you are sending out in .CreateHTMLBody is what you need sent...
0
 

Author Comment

by:Forjey
ID: 18858219
It does send the email and looks as I want it to, it's just stopping the images from embedding themselves and just link directly to minimise the file size.

I've been reading through the Microsoft site, and by default CDO embeds images, so I'm having a play with the Flags. "cdoSuppressImages" seems to be the most likely, but that might kill the images altogether. And so far it does bugger all.

The page that it's sending does have all the image addresses as absoloutes, but that means nothing to cdo apparantly.

I may have to rethink how I'm sending the emails, unless there's a trick I'm missing...

And thank you again for your time.
0
 
LVL 16

Accepted Solution

by:
golfDoctor earned 400 total points
ID: 18860190
Use XMLHTTP to grab the page you want to send and put it in .HTMLBody, not CreateMHTMLBody.  CreateMHTMLBody encapsulates the entire page, causing the embedding.

If you use XMLHTTP you can just use the raw HTML from the page, including links back to your site for the images instead of embedding.

This also means that the source image paths "src" should be full path ("http://.../myimages/imagename.gif"), not relative ("/myimages/imageame.gif").
0
 
LVL 16

Expert Comment

by:golfDoctor
ID: 18860196
0
 
LVL 25

Expert Comment

by:kevp75
ID: 18860239
>>
This also means that the source image paths "src" should be full path ("http://.../myimages/imagename.gif"), not relative ("/myimages/imageame.gif").
<<

which is exactly what I already said...

You should not need to do any kind of scraping at all, .CreateHTMLBody is supposed to send out an HTML email, not encapsulating the entire page.  (experts please do a bit more reading, beofre leading someone in the wrong direction...)

First thing you really need to look at is the fact that you are trying to send a page as an email, rather than sending content:
ObjMail.CreateMHTMLBody ""&Location&"/campaign.asp?intID="&request.form("intID")&"&Campaign="&rsCampaign("ID")&"&rID="&rsRecipient("ID")&""

does not work well at all...
what you should do, is build the HTML page campaign.asp with whatever coding you need, and store it as a variable on the same page that you are trying to send this email from.  Then change:
ObjMail.CreateMHTMLBody ""&Location&"/campaign.asp?intID="&request.form("intID")&"&Campaign="&rsCampaign("ID")&"&rID="&rsRecipient("ID")&""

to:
ObjMail.CreateMHTMLBody theVariableThatContainsTheHTMLCode
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Expert Comment

by:golfDoctor
ID: 18860272
Read kevp75 .CreateMHTMLBody (see the M)
http://msdn2.microsoft.com/en-us/library/ms527024.aspx

We've already seen you're lack of experience, so why continue to show it.  Stop responding to other "Experts", and focus on the asker.  Enough already.
0
 
LVL 25

Expert Comment

by:kevp75
ID: 18860531
just had to go there didn't you!?  (have a look at either one of ours profiles, and then tell me who's got the lack of experience...)

you've just proved what I stated...so thank you
and yes, my comment were mostly directed at the questioner


@Forjey
What it looks like you are trying to do is send an attached file, rather than sending an HTML email...
0
 
LVL 16

Expert Comment

by:golfDoctor
ID: 18860536
Forjey - Sorry if this thread is now hard to follow.  I will restate.  To replicate what you want to do, one method would be to use XMLHTTP to scrape the campaign.asp URL you have (example provided in my link)

Then you would use the responsetext from XMLHTTP and put in objMail.HTMLBody instead of using CreateMHTMLBody.

That should solve your problem.
0
 

Author Comment

by:Forjey
ID: 18860689
Hi guys,

Thanks to both of you for your comments (some history here I gather :)

Kevp75: The reason the string is as coded is due to the variables involved - I'm only sending those variables to identify the campaign and the recipient for 2 reasons - the campaign ID sets all the subsequent variables in the page, and the UserID identifies the recipient to prime the unsubscribe link. There's likely a more elegant way to do this, but I'm just finding my way at the moment.

golfDoctor: The xmlhttp idea sounds interesting - I had almost decided to construct each email using:

strMail & strmail="Code here"

And .htmlbody, but your method would save a lot of recoding. Heh, it's almost typical of Microsoft - they set CDONTS up to be a pain in the ass, and then CDO is just too clever for its own good. *Sigh*

I'm going to give the xmlhttp idea a bash, but I do value input from both of you - the fact that anyone gives a monkeys is a great motivator! If it comes to it I'll up the point value and split between you for your time and effort. Thanks again, I'll let you know how I get on.
0
 
LVL 25

Expert Comment

by:kevp75
ID: 18860722
now see...

it would never be that I'm just blind right...it must be that I'm in-experienced...

no, I did not see the M....and yes...HTMLBody would be a much better idea, however, I am not so sure about the scraping bit.  It would be better to put all the content into a variable, however using the XMLHTTP object would probably not be the best way to do it.

I would say, build the content(into a variable)  on the same page you are sending the email out from, and sending like gd stated with HTMLBody
0
 
LVL 16

Expert Comment

by:golfDoctor
ID: 18860734
XMLHTTP is really quite simple.  You wouldn't need to concatenate anything.  You can use this.

<%
  Response.Buffer = True
  Dim objXMLHTTP, xml

  ' Create an xmlhttp object:
  Set xml = Server.CreateObject("Microsoft.XMLHTTP")
  ' Or, for version 3.0 of XMLHTTP, use:
  ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

  ' Opens the connection to the remote server.
URL = ""&Location&"/campaign.asp?intID="&request.form("intID")&"&Campaign="&rsCampaign("ID")&"&rID="&rsRecipient("ID")&""
  xml.Open "GET", URL, False
      
  ' Actually Sends the request and returns the data:
  xml.Send

  'this is your page content
  emailbody = xml.responseText

  Set xml = Nothing

Set ObjMail = CreateObject("CDO.message")
  ObjMail.FROM = rsUser("userEMAIL")
  ObjMail.TO = rsRecipient("Email")
  ObjMail.Subject = rsCampaign("CampaignName")
  ObjMail.HTMLBody emailbody 'put page content in you email
  ObjMail.Send

%>

0
 
LVL 16

Expert Comment

by:golfDoctor
ID: 18860900
I forgot the =
ObjMail.HTMLBody = emailbody

That code should run just like you want.
0
 

Author Comment

by:Forjey
ID: 18861565
Genius ^^

There were a few issues that needed resolving, so I'll paste the code I ended up using below. Main issue was moving up the "Set Objmail" line so that it didn't try to execute an objmail variable before it was defined, but the xml achieved the exact desired results. Thank you both very much, you've been very helpful!

While NOT rsRecipient.EOF

Set ObjMail = CreateObject("CDO.message")

  Response.Buffer = True
  Dim objXMLHTTP, xml

  ' Create an xmlhttp object:
  Set xml = Server.CreateObject("Microsoft.XMLHTTP")
  ' Or, for version 3.0 of XMLHTTP, use:
  ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

  ' Opens the connection to the remote server.
  ObjMail.CreateMHTMLBody ""&Location&"/campaign.asp?intID="&request.form("intID")&"&Campaign="&rsCampaign("ID")&"&rID="&rsRecipient("ID")&""

 xml.Open "GET", ""&Location&"/campaign.asp?intID="&request.form("intID")&"&Campaign="&rsCampaign("ID")&"&rID="&rsRecipient("ID")&"", False
     
  ' Actually Sends the request and returns the data:
  xml.Send

  'this is your page content
  emailbody = xml.responseText

  Set xml = Nothing

  ObjMail.FROM = rsUser("userEMAIL")
  ObjMail.TO = rsRecipient("Email")
  ObjMail.Subject = rsCampaign("CampaignName")
  ObjMail.HTMLBody = emailbody 'put page content in you email
  ObjMail.Send
   
  rsRecipient.movenext
  wend
  rsRecipient.close
  end if
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This video teaches users how to migrate an existing Wordpress website to a new domain.

708 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

12 Experts available now in Live!

Get 1:1 Help Now