Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Mickers Outlook COM MSDN for Ahk_L


  • Please log in to reply
35 replies to this topic
evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

If your using COM to automat outlook you may be able to use ".SentOnBehalfOfName" insted of ".from"

Confirmed working, thankyou!



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Yet another question I am afraid...

 

If you, for example, send an email to yourself via exchange, the SenderEmailAddress property of the MailItem does not look like an email address.

 

ie, instead of the string peter.jones@mycompany.com, you get something like: /O=TESTNET/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=B8367B91BE4C4C01A3BB1C942751D1FD-PETER JONES

 

Does anyone know how to either resolve this to their primary SMTP address, or if there is another property which holds the primary SMTP address?



kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013
; http://answers.microsoft.com/en-us/office/forum/office_2007-customize/need-vba-to-obtain-smtp-address-of-exchange-user/97833c7c-18e3-4b8d-923a-606b81c9ecd1?auth=1
olApp := ComObjActive("Outlook.Application")
olNamespace := olApp.GetNamespace("MAPI")
Window := olApp.ActiveWindow 
if (Window.Class = 35) ; 35 = An Inspector object. (The email is open in its own window)
{
  SmtpAddress := ""
  MailItem := Window.CurrentItem
  FromName := MailItem.SenderName
  Recip := olApp.Session.CreateRecipient(FromName)
  Recip.Resolve
  if (Recip.Resolved)
  {
    UserType := Recip.AddressEntry.AddressEntryUserType
    if (UserType = 0 || UserType = 10) ; olExchangeUserAddressEntry || olOutlookContactAddressEntry
      SmtpAddress := Recip.AddressEntry.GetExchangeUser.PrimarySmtpAddress
    else if (UserType = 1) ; olExchangeDistributionListAddressEntry
      SmtpAddress := Recip.AddressEntry.GetExchangeDistributionList.PrimarySmtpAddress
  }
  if (SmtpAddress = "")
    SmtpAddress := MailItem.SenderEmailAddress
}
MsgBox, % "SmtpAddress: " SmtpAddress
return


evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

I am trying to iterate through MailItems in a folder, and on some PCs the loop iterates one way (oldest->newest), but on some PCs it iterates the other way (newest->oldest).

Same version of Outlook, same OS, different results. I'm stumped.

I tried to do a Sort, but I cannot seem to get it to change anything.

 

Any ideas?

#SingleInstance force
folder := 6
 
mail := ComObjActive("Outlook.Application").GetNameSpace("MAPI").GetDefaultFolder[folder]
;mail.Items.Sort("[ReceivedTime]", False)
oExp := ComObjActive("Outlook.Application").ActiveExplorer
oExp.ClearSelection
msgbox Nothing should be selected
 
Loop % mail.Items.Count {
mi := A_Index
MailItem := mail.Items[mi]
oExp.ClearSelection
; Select message
oExp.AddToSelection(MailItem)
MsgBox, 4, Confirm Step, % "Item " A_Index " selected with subject " MailItem.Subject ".`nContinue?"
IfMsgBox No
{
break
}
 
}


kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013
mail := ComObjActive("Outlook.Application").GetNameSpace("MAPI").GetDefaultFolder(6)
oExp := ComObjActive("Outlook.Application").ActiveExplorer
MyItems := mail.Items
MyItems.Sort("[Received]", true)
 
for MailItem, in  MyItems {
; Or
;Loop, % MyItems.Count {
;    MailItem := MyItems.Item(A_Index)
    oExp.ClearSelection
    oExp.AddToSelection(MailItem)
    MsgBox, 4, Confirm Step, % "Item " A_Index " selected with subject " MailItem.Subject ".`nContinue?"
    IfMsgBox No
    {
        break
    }
}

Explanation: MailItem Collection Order for a folder



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Thankyou Kon, that worked.

Here is a code snippet to automate the Outlook 2007 "Account" button:

HRVbTUM.png

Adapted from sample VB code

static ID_ACCOUNTS := 31224
desiredaccount := "me@there.com"
oOutlook := ComObjActive("Outlook.Application")
oInspector := oOutlook.Application.ActiveInspector

CBs := oInspector.CommandBars
CBP := CBs.FindControl(, ID_ACCOUNTS)
for MC in CBP.Controls {
	if (InStr(MC.Caption, desiredaccount)){
		MC.Execute
	}
}