Sign in to follow this  
Followers 0
Jewtus

Sending an outlook email with HTMLbody

9 posts in this topic

This is the code that I'm executing. 

$HTMLsource=FileRead('C:\Users\n811761\Desktop\Test.htm')
            $emailAddress = 'Test@Fake.com'
            $olApp = ObjCreate("Outlook.Application")
            $olMailItem = 0
            $objMail = $olApp.CreateItem($olMailItem)
            $objMail.Save
            With $objMail
                .To =($emailAddress)
                .Subject = ("Thank You for Contacting!")
                .HTMLBody = ($HTMLsource)
                .Display
            EndWith
            $oOApp = 0

The problem I'm having is that the HTML file has references to image files.

I was looking at GDIPlus, and it seems like I should be able to convert the image files into a string that I can save so the HTML becomes self contained, but I'm not sure exactly how. I've attached a copy of the HTML and its resource files. If someone could steer me in the right direction, that would be great.

test.zip

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

something like this?

#Include <GDIPlus.au3>
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@SystemDir & "\DirectX\Dinput\act_rs.png")
$sCLSID = _GDIPlus_EncodersGetCLSID("BMP")
_GDIPlus_ImageSaveToFileEx($hImage, @ScriptDir & "\act_rs.bmp", $sCLSID)
_GDIPlus_ShutDown()

taken from: >link

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

That's what I needed... I was trying to find that exactly! Much appreciated!

Share this post


Link to post
Share on other sites

My pleasure! ;)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Or you could use my OutllokEX UDF, attach the image and reference using CID as described in the _OL_ItemCreate example.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I was trying to leverage your script water, but I just needed a simple send email function so I didn't want to add a whole UDF. 

I ended up finding this command:

$objMail=$olApp.CreateItemFromTemplate

and

.HTMLBody = StringReplace($objMail.HTMLBody, "%25Hyperlink%25", $strHyperlink)

and I was able to specify the template file which contained the images so I didn't need to transform the images. It also made string replacement much easier with the template file.

Share this post


Link to post
Share on other sites

The big advantage of running obfuscator when compiling a script is that you can strip off any uunused functions. So the overhead of using a UDF is reduced.

But you are right: Anything that can be done using an UDF can be done directly in the script :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The big advantage of running obfuscator when compiling a script is that you can strip off any uunused functions. So the overhead of using a UDF is reduced.

But you are right: Anything that can be done using an UDF can be done directly in the script :)

Obfuscator? guess you are a couple of releases behind. ;)

Use AU3Stripper for that.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Seems my computer is up to date but not my brain :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0