Hey guys,
I am trying to find out how I can send the email by using AHK. I am able to create the VBA in excel, and then send the email. (Please refer to below script) Do you know how I can embed this script into AHK, so I could use AHK to send emails?
/*VBA - Send emails*/
Dim objOutlook As Object
Dim objMail As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With objMail
.to = TO_text
.cc = CC_text
.bcc = BCC_text
.Subject = Sbj_text
.Body = body_text
.Attachments.Add (path_text)
.Send 'Instead of .Display, you can use .Send to send the email _
or .Save to save a copy in the drafts folder
End With
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing
Set rngAttach = Nothing
End Sub
Thanks in advance,
Tina
Email Topic is solved
-
- Posts: 7
- Joined: 22 Aug 2017, 20:11
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Email
AHK and VBA are accessing the same API of Outlook so you do things very similar just with some syntax differences between the languages.WhiteSubway wrote:Hey guys,
I am trying to find out how I can send the email by using AHK. I am able to create the VBA in excel, and then send the email. (Please refer to below script) Do you know how I can embed this script into AHK, so I could use AHK to send emails?
/*VBA - Send emails*/
Dim objOutlook As Object
Dim objMail As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With objMail
.to = TO_text
.cc = CC_text
.bcc = BCC_text
.Subject = Sbj_text
.Body = body_text
.Attachments.Add (path_text)
.Send 'Instead of .Display, you can use .Send to send the email _
or .Save to save a copy in the drafts folder
End With
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing
Set rngAttach = Nothing
End Sub
Thanks in advance,
Tina
Code: Select all
objOutlook := ComObjCreate("Outlook.Application")
objMail := objOutlook.CreateItem(0)
objMail.to := TO_text
objMail.cc := CC_text
objMail.bcc := BCC_text
objMail.Subject := Sbj_text
objMail.Body := body_text
objMail.Attachments.Add(path_text)
objMail.Display
;~ objMail.Save
;~ objMail.Send
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Email
A more robust example:
FG
Code: Select all
Account := "[email protected]"
Recipients := ["Them <[email protected]>", "We <[email protected]>"]
RecipientsCC := ["Us <[email protected]>", "Those <[email protected]>"]
RecipientsBCC := ["Sneaky <[email protected]>", "Very Sneaky <[email protected]>"]
Subject := "Reports"
Body =
(Join
<a href="http://www.ahkscript.org/">http://www.ahkscript.org/</a><br>
<img src="%A_Desktop%\Test\TestPicture.jpg" />
)
for Index, Recipient in Recipients ; Conditional Body based on Recipients
if Recipient ~= "Them"
{
Body =
(Join
%Body%
<br><a href="http://www.ahkscript.org/them">http://www.ahkscript.org/them</a>
)
break
}
;example of creating a MailItem and setting it's format to HTML
olApp := ComObjCreate("Outlook.Application")
olEmail := olApp.CreateItem(0) ; olMailItem := 0
olNameSpace := olApp.GetNamespace("MAPI")
olEmail.SendUsingAccount := olNameSpace.Accounts.Item(Account)
olEmail.BodyFormat := 2 ; olFormatHTML := 2
olEmail.Subject := Subject
olEmail.HTMLBody := Body
for Index, Recipient in Recipients
olRecipient := olEmail.Recipients.Add(Recipient), olRecipient.Type := 1 ; To: CC: = 2 BCC: = 3
for Index, RecipientCC in RecipientsCC
olRecipient := olEmail.Recipients.Add(RecipientCC), olRecipient.Type := 2 ; To: CC: = 2 BCC: = 3
for Index, RecipientBCC in RecipientsBCC
olRecipient := olEmail.Recipients.Add(RecipientBCC), olRecipient.Type := 3 ; To: CC: = 2 BCC: = 3
olEmail.Attachments.Add(A_Desktop "\Test\Slinky.jpg")
olEmail.Display
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
-
- Posts: 7
- Joined: 22 Aug 2017, 20:11
Re: Email
it works now! You are amazing!
Thanks
Tina
Thanks
Tina
-
- Posts: 7
- Joined: 22 Aug 2017, 20:11
Re: Email
Hi guys,
I guess I have one more question as you guys are amazing!
I was wondering how I can read the 'unread' emails (including the subject and the body) by using AHK. I've found below VBA script, but I still have the issue to embed it with AHK.
/* To read the body & subject of the email*/
Private WithEvents myOlItems As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set myOlItems = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub myOlItems_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(item) = "MailItem" Then
Set Msg = item
MsgBox Msg.Subject
MsgBox Msg.Body
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Thanks again,
Tina
I guess I have one more question as you guys are amazing!
I was wondering how I can read the 'unread' emails (including the subject and the body) by using AHK. I've found below VBA script, but I still have the issue to embed it with AHK.
/* To read the body & subject of the email*/
Private WithEvents myOlItems As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set myOlItems = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub myOlItems_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(item) = "MailItem" Then
Set Msg = item
MsgBox Msg.Subject
MsgBox Msg.Body
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Thanks again,
Tina
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Email Topic is solved
This is fairly simple if you know the structure of the object.WhiteSubway wrote:I was wondering how I can read the 'unread' emails (including the subject and the body) by using AHK. I've found below VBA script, but I still have the issue to embed it with AHK.
Code: Select all
olApp := ComObjActive("Outlook.Application") ; Use Create if Outlook is not going to be open
olNameSpace := olApp.GetNamespace("MAPI")
olFolder := olNameSpace.Folders("My Account Name").Folders("Inbox") ; Get the Folder you want going down as many subfolders as needed
olItems := olFolder.Items.Restrict("[Unread]=true") ; Restrict to only Unread
olItems.Sort("Received", true) ; true or false for descending or ascending
for olItem in olItems
MsgBox % olItem.Subject "`n" olItem.Body ; Any valid Item property will work here
Once you have the Folder you want you get the Items from the Folder with an "Unread" Restrict or what ever status you want, then I like to Sort the Items by Received because they are not always stored internal in the order you might expect.
Then loop through and do what you want with each email.
Also I showed how to pick a specific folder but you can also use a DefaultFolder like in your VBA code.
Change the Folder line to something like this:
olFolder := olNameSpace.GetDefaultFolder(6) ; 6 = olFolderInbox
VBA has the constants built in but with AHK you have to put the actual value.
Below is a list of the default folder values:
Constant Value
olFolderCalendar 9
olFolderContacts 10
olFolderDeletedItems 3
olFolderDrafts 16
olFolderInbox 6
olFolderJournal 11
olFolderJunk 23
olFolderNotes 12
olFolderOutbox 4
olFolderSentMail 5
olFolderTasks 13
olPublicFoldersAllPublicFolders 18
olFolderConflicts 19
olFolderLocalFailures 21
olFolderServerFailures 22
olFolderSyncIssues 20
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
-
- Posts: 7
- Joined: 22 Aug 2017, 20:11
Re: Email
Hi guys,
I've seen this post showing how to get the e-mail date and time from Outlook.
https://autohotkey.com/board/topic/1153 ... m-outlook/
I am trying to add it to the previous script (which FanaticGuru helped me come with.), so I can get the time & the date of the email.
Could you please a bit assistance again?
Thanks
Tina
I've seen this post showing how to get the e-mail date and time from Outlook.
https://autohotkey.com/board/topic/1153 ... m-outlook/
I am trying to add it to the previous script (which FanaticGuru helped me come with.), so I can get the time & the date of the email.
Could you please a bit assistance again?
Thanks
Tina
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Email
Once you get the olItem in my examples above you can get any of the other properties of an email object the same as you do Subject and Body.WhiteSubway wrote:Hi guys,
I've seen this post showing how to get the e-mail date and time from Outlook.
https://autohotkey.com/board/topic/1153 ... m-outlook/
I am trying to add it to the previous script (which FanaticGuru helped me come with.), so I can get the time & the date of the email.
Could you please a bit assistance again?
Thanks
Tina
Here is a link to the mailitem object:
https://msdn.microsoft.com/en-us/vba/ou ... ct-outlook
You can use any of the Properties at the bottom. You probably want olItem.ReceivedTime
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
-
- Posts: 7
- Joined: 22 Aug 2017, 20:11
Re: Email
Thanks again! I think that's what exactly I am looking for.
Cheers,
Tina
Cheers,
Tina
-
- Posts: 7
- Joined: 22 Aug 2017, 20:11
Re: Email
Hi guys,
I am seeking for a big help here again. I am trying to figure it out myself but it's really scratch my head.
I am trying to document the main process in the plain English. Could someone help me build up in AHK language which will be compatible with our other applications?
Thanks muchly,
Tina
Process
1) Login to outlook (application)
2) Make sure the outlook is open correctly
*If the user can see ‘Inbox – [email protected]’ - Outlook on the top of the page
3) Scroll down to the SHR PICS email box
4) Click the SHR PICS email box name and make sure it is the correct shared email box. * If the user can see ‘SHR PICS – Outlook’ on the top of the page
5) Check if there are any new emails in the targeted email box
6) Check if the new emails are from the internal senders (e.g. [email protected])
7) If the emails are met above 2 conditions, then send an auto reply with ‘Thanks for your email. We will review your request & response to you as soon as possible’ by clicking reply button.
8) After the email has been sent out, move the emails into ‘Working in Process’ folder under the user email account (e.g. [email protected]) by right clicking ‘move’ and selecting the destination folder.
9) If the emails are not met condition 6), then send an auto reply with ‘Sorry, we cannot accept your request at the current stage. Please ring 123 for the general questions….’
I am seeking for a big help here again. I am trying to figure it out myself but it's really scratch my head.
I am trying to document the main process in the plain English. Could someone help me build up in AHK language which will be compatible with our other applications?
Thanks muchly,
Tina
Process
1) Login to outlook (application)
2) Make sure the outlook is open correctly
*If the user can see ‘Inbox – [email protected]’ - Outlook on the top of the page
3) Scroll down to the SHR PICS email box
4) Click the SHR PICS email box name and make sure it is the correct shared email box. * If the user can see ‘SHR PICS – Outlook’ on the top of the page
5) Check if there are any new emails in the targeted email box
6) Check if the new emails are from the internal senders (e.g. [email protected])
7) If the emails are met above 2 conditions, then send an auto reply with ‘Thanks for your email. We will review your request & response to you as soon as possible’ by clicking reply button.
8) After the email has been sent out, move the emails into ‘Working in Process’ folder under the user email account (e.g. [email protected]) by right clicking ‘move’ and selecting the destination folder.
9) If the emails are not met condition 6), then send an auto reply with ‘Sorry, we cannot accept your request at the current stage. Please ring 123 for the general questions….’
Re: Email
Hi
I´am pretty new on this - and also very interested in making a script that allows me to get the e-mail date and time from Outlook. My mission is to copy e-mails in Outlook and paste the files (.msg) into a folder in Onedrive and with an AutoHotkey rename and organize by adding date and time as follow: "2018-04-14 18.58 - Mail". I am capable of pasting in current time or file creation time - but this I can´t solve by my self. Can anybody help me getting further with a script
I´am pretty new on this - and also very interested in making a script that allows me to get the e-mail date and time from Outlook. My mission is to copy e-mails in Outlook and paste the files (.msg) into a folder in Onedrive and with an AutoHotkey rename and organize by adding date and time as follow: "2018-04-14 18.58 - Mail". I am capable of pasting in current time or file creation time - but this I can´t solve by my self. Can anybody help me getting further with a script
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Email
Here is an exmaple script showing how to save a selected or open email to a msg file.TheGGG wrote:Hi
I´am pretty new on this - and also very interested in making a script that allows me to get the e-mail date and time from Outlook. My mission is to copy e-mails in Outlook and paste the files (.msg) into a folder in Onedrive and with an AutoHotkey rename and organize by adding date and time as follow: "2018-04-14 18.58 - Mail". I am capable of pasting in current time or file creation time - but this I can´t solve by my self. Can anybody help me getting further with a script
Code: Select all
F12::
olApp := ComObjActive("Outlook.Application")
try
olItem := olApp.ActiveWindow.CurrentItem
catch
olItem := olApp.ActiveExplorer.Selection.Item(1)
if (olItem.Class = 43)
olMailItem := olItem
else
{
MsgBox Mail Item Not Current or Selected
return
}
FilePathName := A_ScriptDir "\" RegExReplace(olMailItem.Subject, "[\?<>/\\\*""|:]") ".msg"
olMailItem.SaveAs(FilePathName, 3) ; 3 = SaveAs msg file format
return
It is important to make sure the path/name does not contain any invalid characters which is what the RegExReplace does in my example. It strips out specific invalid characters.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: Email
OK, that (unanswered) request is about 2yrs old. Haven't there been Outlook's filter-options already available? Well, I do think so.WhiteSubway wrote: ↑14 Mar 2018, 23:17Hi guys,
I am seeking for a big help here again. I am trying to figure it out myself but it's really scratch my head.
I am trying to document the main process in the plain English. Could someone help me build up in AHK language which will be compatible with our other applications?
Thanks muchly,
Tina
[...]