creating a new email from GUI with several attachments
Posted: 01 Apr 2017, 16:52
Hello
In the first, and perhaps the last gui before I learn proper syntax I need to create a form that enables users to input (outlook) email address, recipient's name along with a few variables in the body. The rest of the body would be a predetermined message + attachments from set folders (with filenames changing a bit periodically). The output would be a new unsent email. I've found 2 scripts whose combination would resolve the issue. As much as I tried to combine the two, the output would show the qualities of either but not both. I do realize that I'm playing alchemist where an engineer is needed so I'd appreciate any assistance in this .
The two scripts in question are:
Synkfaze's (ideal for my purpose since there will always be two files to be attached in a folder with filenames changing a bit but always retaining core name, and I do *corename* instead of file extension in this case)
and stjung's (from the post I read I inferred it had a mistake but it worked for me since I had different variables)
I already have a working GUI but this would have to be implemented in its several tabs.
I have another question: Would it be possible to add attachments between the paragraphs in the body? A paragraph, then an attachment, then another paragraph and attachment. The paragraphs are predetermined.
In the first, and perhaps the last gui before I learn proper syntax I need to create a form that enables users to input (outlook) email address, recipient's name along with a few variables in the body. The rest of the body would be a predetermined message + attachments from set folders (with filenames changing a bit periodically). The output would be a new unsent email. I've found 2 scripts whose combination would resolve the issue. As much as I tried to combine the two, the output would show the qualities of either but not both. I do realize that I'm playing alchemist where an engineer is needed so I'd appreciate any assistance in this .
The two scripts in question are:
Synkfaze's (ideal for my purpose since there will always be two files to be attached in a folder with filenames changing a bit but always retaining core name, and I do *corename* instead of file extension in this case)
Code: Select all
mailItem := ComObj("Outlook.Application").CreateItem(0) ; creates new mail item
Loop, path to Excel files\*.xlsx ; or .xls, whichever
mailItem.Attachments.Add(A_LoopFileLongPath) ; attaches each file
mailItem.GetInspector.Display() ; makes mail item visible
Code: Select all
Gui, Add, Text,, RECIPIENT NAME
Gui, Add, Edit, vRecipient
Gui, Add, Text,, RECIPIENT EMAIL
Gui, Add, Edit, vEmail
Gui, Add, Text,, TOPIC
Gui, Add, Edit, vTopic
Gui, Add, Edit, vMyFile,
GUI, Add, Button, ym gBtnBrowse, &Browse
Gui, Show
Gui, Add, Button, gAddText, Compose
Gui, Show, AutoSize Center, Email generator
Return
AddText:
gui, submit
Outlook := ComObjActive("Outlook.Application")
email := Outlook.Application.CreateItem(0)
email.To := Email
email.Body := "Dear " Recipient ",`r`nThank you for contacting me.`r`n`Here is the file about " Topic "."
email.Subject := Your requested information about " topic
email.Attachments.Add(SelectedFile, 1, 1, SelectedFile)
email.Display(true)
Gui, Destroy
Return
BtnBrowse:
FileSelectFile,SelectedFile
If SelectedFile
GuiControl,, MyFile, %SelectedFile%
return
I have another question: Would it be possible to add attachments between the paragraphs in the body? A paragraph, then an attachment, then another paragraph and attachment. The paragraphs are predetermined.