Can't embed image using CDO in VBScript

I need a solution in either VBScript or JScript to use CDO to send an embedded image in an email. Here's the closest i've gotten, i've been working on this all day :(

I get the following error:
BC30807: 'Let' and 'Set' assignment statements are no longer supported.
Referencing the line: "Set objBP = objCDO.AddRelatedBodyPart(Ser"...

Environment: Windows 2008 Server RC2, IIS 7

<%@ Page Language="VBScript" Debug="true"%>
<%
Dim objBP
Dim objCDO = CreateObject("CDO.Message") 
objCDO.Subject = "subject"
objCDO.From = "my@address.com" 
objCDO.To = "your@address.com"
objCDO.HTMLBody = "The image: <img src='cid:myimage.gif'>"

Set objBP = objCDO.AddRelatedBodyPart(Server.MapPath("/images/myimage.gif"), "myimage.gif", 1)
objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<myimage.gif>"
objBP.Fields.Update

objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")="my@address.com" 
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")="mypassword"
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.gmail.com"
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")=1
objCDO.Configuration.Fields.Update

objCDO.Send
%>

Open in new window


Thanks guys!
GrrWolfieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
See if this works.....

Dim objBP
Dim objCDO
Set objCDO = CreateObject("CDO.Message") 
objCDO.Subject = "subject"
objCDO.From = "my@address.com" 
objCDO.To = "your@address.com"
objCDO.HTMLBody = "<html>The image: <img src=""cid:myimage.gif""></html>"

Set objBP = objCDO.AddRelatedBodyPart(Server.MapPath("/images/myimage.gif"), "myimage.gif", 1)
objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<myimage.gif>"
objBP.Fields.Update

objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")="my@address.com" 
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")="mypassword"
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.gmail.com"
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")=1
objCDO.Configuration.Fields.Update

objCDO.Send

Open in new window


Perhaps try it outside of ASP and use a straight VBS first, just to see if it works (after changing the server.mappath part).

Rob.
0
GrrWolfieAuthor Commented:
Sadly I have no idea how to do that lol, I did try replacing the <% ...code... %> tags with <script runat="server" language="vb"> ...code... </script>

After that I get
BC30188: Declaration expected.
regarding line:
objCDO.Subject = "subject"
0
GrrWolfieAuthor Commented:
This may be the solution here... I'll try it out within the next few days and post if it works: http://www.systemnetmail.com/faq/4.4.aspx

Apparently you need to use System.Net.Mail unless your using classic ASP in which case your using scriptmail.intermedia.net.

Additional resource: http://hosting.intermedia.net/support/kb/default.asp?id=1579 (has fix information including stuff on classic ASP cdosys)
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

RobSampsonCommented:
To try it as a plain VBS, outside of ASP, copy the code to Notepad, then click File --> Save As, and save it as "SendMail.vbs", including the quotes, to make sure it stays as a VBS file, and not TXT.

Then double-click that vbs file in Windows Explorer to run it.

Regards,

Rob.
0
GrrWolfieAuthor Commented:
Thanks for the reply Rob, I tried the code in VBS and I get the error "Object doesn't support this property or method" when it gets to objCDO = CreateObject("CDO.Message")

I also tried running the system.net.mail code in the link above and the code will run with no errors but no email will be sent. I'm assuming it's placing it in an outbox somewhere for some other service to send out which is not what I want.

If I can just get around the "'Let' and 'Set' assignment statements are no longer supported." error in the first post i'd be 100% good to go :X
0
GrrWolfieAuthor Commented:
oh forgot to mention, if I remove the 3 embed image lines in my 1st post it sends the email perfectly. The problem really is just finding and alternative for "Set".
0
GrrWolfieAuthor Commented:
Problem solved, below is all the code you need. Thanks Rob for the assistance :)

Also worthy of note... it won't work if you use "cid:" in the src part of the image tags in the body (wasted hours on that). It needs to just be the image name as stated in AddRelatedBodyPart with no "cid:" or path information.

<%@ Page Language="VBScript" Debug="true"%>
<%
Dim objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "a subject"
objMessage.From = "from@address.com" 
objMessage.To = "to@address.com" 
objMessage.HTMLBody = "<html>Test Body<img src="test.jpg"></html>"
objMessage.AddRelatedBodyPart("C:\inetpub\wwwroot\test.jpg","test.jpg",1)
objMessage.Configuration.Fields.Item("urn:schemas:mailheader:Content-ID").Value = "<test.jpg>"
objMessage.Configuration.Fields.Update()

objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")="your username"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")="your password"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.gmail.com"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")=1
objMessage.Configuration.Fields.Update

objMessage.Send

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobSampsonCommented:
Very good. Thanks for the grade.

Rob.
0
GrrWolfieAuthor Commented:
My answer solves the problem, rob assisted in the process.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.