Connecting Tech Pros Worldwide Forums | Help | Site Map

Embedding images and dynamic content in an email, programmatically

Chris Nafziger
Guest
 
Posts: n/a
#1: Jul 19 '05
In my code to send email from VBScript, I use standard CDOSYS code similar to
the following:

With oMsg
Set .Configuration = oCon
.To = """Admin"" <admin@mycompany.com>"
.From = """Joe Admin"" <jadmin@mycompany.com>"
.Subject = "Hey You!"
.TextBody = "Service(s) have failed!"
.Send
End With

I understand the use of the .HTMLBody property, as well as the
..CreateMHTMLBody method. So I know I can create an ASP or HTML page, and
pass it to the .CreateMHTMLBody method, to get the images truly embedded, so
the email source contains the cid:blahblahblah references to the images,
which is key to getting the email to display properly in web-based mail
clients.

My question is... how do I achieve the same thing (embed the images) that
the .CreateMHTMLBody method does automatically, manually, so I can also
inject values passed from a form postback into the email?

It seems that I shouldn't use the .CreateMHTMLBody method. It seems that I
need to manually accomplish what it accomplishes automatically, so I have
more granular control. But I have found no thorough online resources that
explain exactly how. I have thoroughly looked at all of the SDK information
pertaining to CDOSYS, and I am still in dire need of an example for
VBScript...

It seems that the .AddRelatedBodyPart method is part of the answer, but when
I use it to embed the images and fill .HTMLBody, rather than using the
..CreateMHTMLBody method, I do not see cid:blahblahblah in the email source,
and the images do not display properly in web-based mail clients such as
Outlook Web Access.

I really need some help on this. It would also appear that I am not alone.
I find plenty of questions on this, but no answers. Can anyone help with a
working VBScript example that embeds images into an email in a fashion that
yields the cid:blahblahblah in the email source, for the image references,
that does not use the .CreateMHTMLBody method to do the work automatically?




Alex Deveza
Guest
 
Posts: n/a
#2: Jul 19 '05

re: Embedding images and dynamic content in an email, programmatically


The answer is to use .addRelatedBodyParts, the example that they provide is
missing something, the place where "..src=""xyz.gif"" is mentioned, you
should modify the HTML to say "...src=""cid:xyz.gif"", and reference
"xyz.gif" when you call addRelatedBodyParts. I was working on these for days,
and by just mere luck, I stumble onto it...hope this helps.

Alex

"Chris Nafziger" wrote:
[color=blue]
> In my code to send email from VBScript, I use standard CDOSYS code similar to
> the following:
>
> With oMsg
> Set .Configuration = oCon
> .To = """Admin"" <admin@mycompany.com>"
> .From = """Joe Admin"" <jadmin@mycompany.com>"
> .Subject = "Hey You!"
> .TextBody = "Service(s) have failed!"
> .Send
> End With
>
> I understand the use of the .HTMLBody property, as well as the
> .CreateMHTMLBody method. So I know I can create an ASP or HTML page, and
> pass it to the .CreateMHTMLBody method, to get the images truly embedded, so
> the email source contains the cid:blahblahblah references to the images,
> which is key to getting the email to display properly in web-based mail
> clients.
>
> My question is... how do I achieve the same thing (embed the images) that
> the .CreateMHTMLBody method does automatically, manually, so I can also
> inject values passed from a form postback into the email?
>
> It seems that I shouldn't use the .CreateMHTMLBody method. It seems that I
> need to manually accomplish what it accomplishes automatically, so I have
> more granular control. But I have found no thorough online resources that
> explain exactly how. I have thoroughly looked at all of the SDK information
> pertaining to CDOSYS, and I am still in dire need of an example for
> VBScript...
>
> It seems that the .AddRelatedBodyPart method is part of the answer, but when
> I use it to embed the images and fill .HTMLBody, rather than using the
> .CreateMHTMLBody method, I do not see cid:blahblahblah in the email source,
> and the images do not display properly in web-based mail clients such as
> Outlook Web Access.
>
> I really need some help on this. It would also appear that I am not alone.
> I find plenty of questions on this, but no answers. Can anyone help with a
> working VBScript example that embeds images into an email in a fashion that
> yields the cid:blahblahblah in the email source, for the image references,
> that does not use the .CreateMHTMLBody method to do the work automatically?
>
>
>[/color]
Closed Thread