Jump to content
Sign in to follow this  
zotchy

Open an email from template with modified values from GUI

Recommended Posts

zotchy

Dear Colleagues,

I have a task to generate an email from GUI.

This is what I have.

1. GUI with some drop-down lists;

2. Some template in HTML (or msg format) with markers.

I need to generate an email. Script should open a template, replace markers with values from GUI and open it in MSG format. To, BC, BCC, Subject should be filled as well to allow me to make some modifications and press Send button.

Do you have some scripts for that?

Thank you very much for the help.

Share this post


Link to post
Share on other sites
water

Which mail program do you use?


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
zotchy

Which mail program do you use?

Thanks for reply

I have an Outlook

Share this post


Link to post
Share on other sites
water

In this case you should have a look at my OutlookEX UDF (for download please see the signature).

To open a template use function _OL_ItemCreate.


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
zotchy

In this case you should have a look at my OutlookEX UDF (for download please see the signature).

To open a template use function _OL_ItemCreate.

I have a problem creating mail based on a template.

When I use function _OL_ItemCreate it renurns error.

I have a script in standard AutoIt folder "Include". I have template there. I want to create mail in the same folder

$oItem = _OL_ItemCreate($oOutlook, $olMailItem, "*", @ScriptDir & "unplanned_template.oft")

No errors appear, but mail is not being created as well.

Also how should I call this create email? I need to check the content in it and modify it by required values from GUI.

Thank you for help.

Share this post


Link to post
Share on other sites
water

Whats the value of @error and @extended after you called _OL_ItemCreate?


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
zotchy

Whats the value of @error and @extended after you called _OL_ItemCreate?

It returns '0' for both.

Share this post


Link to post
Share on other sites
water

Then there should be a mail in the drafts folder.

To display the mail use:

$oItem = _OL_ItemCreate($oOutlook, $olMailItem, "*", @ScriptDir & "unplanned_template.oft")
$oitem.Display

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
zotchy

Then there should be a mail in the drafts folder.

To display the mail use

It works now! Thanks. What function should we use to modify parameters of $oItem? (replace a text in Body for example)

Share this post


Link to post
Share on other sites
water

Depending on the type of mail (text or html - can be accessed with property $oitem.BodyFormat) you have to access $oItem.Body or $oitem.HTMLBody.

Use function _OL_ItemGet to read the property and _OL_ItemModify to update.


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
zotchy

Depending on the type of mail (text or html - can be accessed with property $oitem.BodyFormat) you have to access $oItem.Body or $oitem.HTMLBody.

Use function _OL_ItemGet to read the property and _OL_ItemModify to update.

Could you please provide me the example? How can I call a particular property? For example field TO:?

Is the syntax correct?

$oItem = _OL_ItemCreate($oOutlook, $olMailItem, "*", @ScriptDir & "unplanned_template.oft")
$aOL_Properties = _OL_ItemGet($oOutlook, $oItem[1][0], Default, "??????")

What options should I use instead of ??????

Thanks

Dmitry

Edited by zotchy

Share this post


Link to post
Share on other sites
water

To set the recipients (To, CC, BCC) you need to use function _OL_ItemRecipientAdd.

Example:

_OL_ItemRecipientAdd($oOutlook, $oItem, Default, $olTo, "Name of Recipient1", "SMTP Mail Address of recipient 2")

To retrieve the body, change and update the mail item use:

$asBody = _OL_ItemGet($oOutlook, $oItem, Default, "Body")
$asBody[1][1] = $asBody[1][1] & @CRLF & "New line"
_OL_ItemModify($oOutlook, $oItem, Default, "Body=" & $asBody[1][1])
Edited by water

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
zotchy

Good. Thank you very much for your help.

But I have a problem with returning values from "Body", "CC" etc.

Once I try to get result of variable $sBody (Item = Body), it returns nothing to MsgBox. So I am not able to update/replace strings.

Thanks

Dmitry

Share this post


Link to post
Share on other sites
water

To work with the To, CC and BCC properties you have to use functions _OL_ItemRecipientAdd, _OL_ItemRecipientDelete and _OL_ItemRecipientGet.

_Ol_ItemGet returns an 2D array. So use _ArrayDisplay($aOL_Properties)

I've modified my above examples accordingly.

Edited by water

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
zotchy

_Ol_ItemGet returns an 2D array. So use _ArrayDisplay($aOL_Properties)

Great. But I have a Body with tables and pictures. Once I try to call array asBody[1][1] and make a replacement, it deletes all formatting and pictures.

Thanks

Share this post


Link to post
Share on other sites
water

Tables and pictures sounds like HTML.

What do you get when you run this code?

$asBody = _OL_ItemGet($oOutlook, $oItem, Default, "BodyFormat")
_ArrayDisplay($asBody)

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
water

Value 2 means: HTML

So you have to retrieve property "HTMLBody" to retain tables and pictures.


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
zotchy

Value 2 means: HTML

So you have to retrieve property "HTMLBody" to retain tables and pictures.

Everything is clear now. Thank you very much for your assistance.

Share this post


Link to post
Share on other sites
water

Glad to be of service :D


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  

  • Similar Content

    • Gowrisankar
      By Gowrisankar
      Dear members,
      I'm trying to move unread mails from Inbox to a different folder using OutlookEx UDF.
      But its not working for me. I'm not sure what mistake I do.
      I get the error code 6 when the following is executed. From the UDF it is observed that  "No or an invalid item has been specified".
      Note : The UDF version is 1.3.3.1. AutoIt version (v3.3.14.2).
      #include <OutlookEX.au3> Global $oOutlook = _OL_Open() If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended) Global $aOL_Item = _OL_ItemFind($oOutlook, "*\Inbox", $olMail, "[UnRead]=True", "", "", "Subject", "", 1) If $aOL_Item[0][0] = 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemMove Example Script", "Could not find a task item in folder 'Outlook-UDF-Test\SourceFolder\Tasks'. @error = " & @error) _ArrayDisplay($aOL_Item, "OutlookEX UDF: _OL_ItemFind Example Script - Unread mails") _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "*\Outlook-UDF-Test\TargetFolder\Mail") If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemMove Example Script", "Error moving specified task. @error = " & @error) Any help is deeply appreciated. Thanks in advance.
      Thanks and regards,
      Gowrisankar R.
    • gf100
      By gf100
      Newbie. I am writing a script that requires me to reference the TO:, FROM:, BCC, SUBJECT, BODY of a new email that's being composed.  I need to go directly to these location and work with them.  Is there anyway to detect these in AUTOIT for the present gmail client screen without knowing its resolution and text size?  Any help is greatly appreciated.
    • ur
      By ur
      We can send mails using SMTP settings in AutoIT.
      But is there anyway to read the mails and start the program if we get the mail with the particular subject.
       
      I mean, I have automated a build process and it starts from windows task scheduler my autoit program at morning 3 AM.
      If it fails in the middle, it will be sent to the dev team guys with the logs as attachment.
      Then I am connecting manually to the remote machine to trigger the task again.
      Is there anyway to start this task once I receive a mail with the specific subject like "start the build" automatically.
       
    • ur
      By ur
      Is there any way to launch an application once I receive an email.
      I have an executable created in autoit and I am running it regularly on daily basis using task scheduler on windows.
      And sometimes I am running it again manually if someone asks to.
      Is there anyway to configure an email so that when I send a mail to that particular email ID then it should launch that exe directly?
    • Rapidnxit
      By Rapidnxit
      Hi! I want to send by mail some files with a certain extension (.xml in my case). These files are located in the script folder. First, I thought to use _FileListToArrayRec function to have a list of these files. But than I don't know how to send them all at once. I know that I can attach multiple files in this way: path1;path2;path3; etc.  and so I have tried to make a string of this type with the path of the files (with a for loop) but It doesn't attach any file (only instructions.txt). How could I do? ( what I did is just an idea, if there's something better that would be great) Thanks!
      $aArrayXml = _FileListToArrayRec(@ScriptDir, "*.xml", $FLTAR_FILES) _ArrayDisplay($aArrayXml, "LIST XML") $LenghtArrayXml = UBound($aArrayXml) If ($LenghtArrayXml > 2) Then For $i = 2 To $LenghtArrayXml - 1 $temp = "&@ScriptDir&""\"&$aArrayXml[$i]&";"&"""" $XmlListFile = $XmlListFile & $temp Next EndIf $XmlListFile = StringTrimLeft($XmlListFile, 1) if($LenghtArrayXml = 2)Then $rc =_INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @ScriptDir&"\"&$aArrayXml[1]&";"&@ScriptDir&"\instructions.txt", $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) Else $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @ScriptDir&"\"&$aArrayXml[1]&$XmlListFile&@ScriptDir&"\instructions.txt", $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) EndIf  
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.