Jump to content

invoke new outlook email with no recipient and one attachment


rudi
 Share

Recommended Posts

Hello,

after doing some searches (keywords as in OP title) I didn's find a native solution here. With Google I found this PowerShell script and here (Answer #1) howto display the Outlook new email window with the prefilled things:

 

$o = New-Object -com Outlook.Application
$mail = $o.CreateItem(0)
 
#2 = High importance message
$mail.importance = 1
 
$mail.subject = "invoice"
$mail.body = "Some body text, ... invoice PDF see attachment, please."
 
#separate multiple recipients with a ";"
$mail.To = "" # no recipients shall be prefilled
#$mail.CC = <OTHER RECIPIENT 1>;<OTHER RECIPIENT 2>
 
# Iterate over all files and only add the ones that have an .html extension
$AttachFPFN = $(Get-ChildItem "C:\temp\invoice.pdf").fullname
 
 
# if the extension is the one we want, add to attachments
$mail.Attachments.Add($AttachFPFN)
$mail.display()

 

I have close to no experience with all the Autoit object functions and was quite astonished, that with the sample code from the help file for ObjCreate() it was quite easy to modify that code to work with Autoit as well:

$oOutlook =ObjCreate("Outlook.Application")
$mail = $oOutlook.CreateItem(0)
$mail.subject = "invoice"
$mail.body = "Some body text, ... invoice PDF see attachment, please."
$mail.To = "" ; no recipients shall be prefilled
$AttachFPFN = "C:\temp\invoice.pdf"
$mail.Attachments.Add($AttachFPFN)
$mail.display()

 

Is it required / recommended to "cleanup / destroy" such Objects after their use? (once the email has been sent), and how to do so?

The script will run in an infinite WHILE loop waiting for new PDFs to show up in the file system in some special folder. 

 

And a final question upon Objects: Is it possible to list the sub-items of an Autoit Object?

 

With PowerShell e.g. I type 

$mail.

[then press STRG+"SPACE" --> "Y" so see all the 123 the subitems]

image.png.0df61db50f2cb155edd9f8e141533c66.png

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Use function _OL_ItemAttachmentAdd to add an attachment to a mail item. See the example script _OL_ItemAttachmentAdd.au3

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

@water

thanks for your suggestion. For the next, different task that's outlook related I'll take a closer look to the UDF you provided.

Probably there is another function in your UDF to open a new Outlook mail, giving back an object, to wich _OL_ItemAttachmentAdd() can add files as attachment?

 

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

You will get a better overview by having a look at the help file (CHM) that comes with the UDF. The function reference is grouped by Outlook objects (mail, appointment ... general).
More detailed information can be found in the AutoIt wiki - or here in the forum.

To create a new mail item use function _OL_ItemCreate. This is a general function because it can create all types of items (mails, notes, appointments ...).

Edited by water

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...