Jump to content

Sending an outlook email with HTMLbody


Jewtus
 Share

Go to solution Solved by MikahS,

Recommended Posts

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

Link to comment
Share on other sites

  • Solution

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

 

Link to comment
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

 

Link to comment
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.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...