
May 16th 09, 10:13 PM
posted to microsoft.public.outlook.program_vba
|
|
Sent Items
So do you want to access POP3/SMTP accounts or use the Exchange mailboxes?
--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"JHP" wrote in message
...
Just getting back to this:
Again thank you for your expertise, I really appreciate you taking the
time here... really!
Is it possible to access that information the way Outlook does (POP3/SMTP)
via script?
I really like the idea of using the GAL - thank you.
"Dmitry Streblechenko" wrote in message
...
Email does not know that, but Outlook does. For the POP3/SMTP accounts,
that information is tored along with the other account related
information, such as the names of the servers.
In case of Exchanage, you would need to read the entry id of the GAL
user, open the user's Sent Items foleer using
Namespace.GetSharedDefaultFolder, then move the message there.
--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"JHP" wrote in message
...
Yes - under User Information - E-mail Address.
If you reverse the process... how does an incoming email know to go to a
particular folder (Account); I would like to know that logic and apply
it here.
When I send an email as someone else I want to move the mail item to the
correct Sent Items folder (if it exists in the current profile), but I
don't want to hard code the Folder Name to the Sender Name as the folder
name may change.
The following is what I did for our Exchange environment
(ThisOutlookSession):
Private WithEvents sentItems As Items
Private Sub Application_Startup()
Dim objNS As NameSpace
Dim objRecipient As Recipient
Dim objFolder As MAPIFolder
Set objNS = Me.GetNamespace("MAPI")
Set objRecipient = objNS.CreateRecipient(objNS.CurrentUser.Address)
objRecipient.Resolve
If objRecipient.Resolved Then
Set objFolder = objNS.GetDefaultFolder(olFolderSentMail)
Set sentItems = objFolder.Items
Set objFolder = Nothing
Else
MsgBox ("Error: Name Not Resolved - Please Contact Your
Administrator")
End If
Set objRecipient = Nothing
Set objNS = Nothing
End Sub
Private Sub sentItems_ItemAdd(ByVal Item As Object)
Dim objItem As Outlook.MailItem
Dim objNS As NameSpace
Const g_PR_SMTP_ADDRESS_W = &H39FE001F
If (TypeOf Item Is Outlook.MailItem) Then
Set objItem = Item
Set objNS = Me.GetNamespace("MAPI")
If objNS.CurrentUser.Name objItem.SentOnBehalfOfName And
objNS.CurrentUser.Name objNS.CurrentUser.Address Then
strEntryID = objItem.EntryID
strStoreID = objItem.Parent.StoreID
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False
Set objMessage = objSession.GetMessage(strEntryID,
strStoreID)
strAddress = objMessage.Sender.Address
If Not InStr(strAddress, "@") Then
On Error Resume Next
strAddress =
objMessage.Sender.Fields(g_PR_SMTP_ADDRESS_W).Valu e
End If
objSession.Logoff
Set objMessage = Nothing
Set objSession = Nothing
Set objFolders = objNS.Folders
For Each rtnFolder In objFolders
strMailbox = rtnFolder.Name
If strMailbox = "Mailbox - " & objItem.SentOnBehalfOfName
Then
Set objSentItems =
objNS.Folders(strMailbox).Folders("Sent Items")
objItem.Move objSentItems
Set objSentItems = Nothing
Exit For
End If
Next
Set objFolders = Nothing
End If
Set objNS = Nothing
Set objItem = Nothing
End If
End Sub
"Dmitry Streblechenko" wrote in message
...
How exactly do you associate an SMTP account with the store? Do you set
where the messages will be delivered in Tools | Accounts?
--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"JHP" wrote in message
...
Thank you for replying Mark McGinty,
Forgetting about the PST file - you have it right that I want to move
the sent items to the "proper" (SentOnBehalfOfName) account - but I
want to accomplish this as the items are being sent, and not have to
hard-code the folder name.
This is a very easy task if I wanted to hardcode the folder name, but
as I have stated in previous posts - I have already accomplished this
in an Exchange environment, but in a "PST" environment the user can
change the Account Name - making SentOnBehalfOfName useless.
Thank you for any insites,
"Mark McGinty" wrote in message
...
"JHP" wrote in message
...
Maybe I need supply more information?
I am trying to determine if a sent email (from address) belongs to
an existing (visible) mailbox...
Lets say I have multiple accounts (PST files as I already have
Exchange folders working) setup - I want to be able to determine
which account the email was sent from.
I don't want to have to hard-code the folder name (Select Case to
match address to folder) as a (PST) mailbox can be renamed.
I thought of using StoreID but a sent email (Parent.StoreID) takes
on the Default account's ID.
Any help would be greatly appreciated,
I'm still a little unclear as to what you're trying to do. You are
talking about an Outlook profile that is configured to sync with
multiple POP3 accounts, correct? It seems like you are inferring
that each POP3 account logically maps to a separate .PST file -- that
is not the case. Mail from all POP3 accounts is delivered to a single
Inbox folder in a single .PST.
When you have multiple configured POP3 accounts you may choose which
you want to send from, when composing; by default the from address
for a reply is dictated by the account on which it was received (but
it is still user-selectable.)
If what you want to do is separate the items in Sent Items, according
to the POP3 account from which it was sent, I think you could get
that by reading the PR_SENDER_EMAIL_ADDRESS property (using extended
MAPI or Redemption) and move the item accordingly. But a separate
destination corresponding to each POP3 will not already exist, you'll
have to create them yourself (presumably as folders under Sent
Items -- as a user I personally would be disenchanted by an AddIn
that created a bunch of .PST files like that.)
-Mark
"JHP" wrote in message
...
I've written a Macro that moves sent email to the proper Mailbox
without hard-coding Mailbox name; working great with Exchange
Accounts, but if this same approch is used with PST Accounts...
I don't know how (where to begin) to match the Sent mail to the
correct folder, as the folder name can be renamed and may not match
the SentOnBehalfOfName?
Thank you for any assistance,
|