Accounts
Let's say I have multiple accounts in Outlook ("bob#example.com" and "bob#gmail.com"):
Mailboxes
Each account can have multiple mailboxes. In this case the account bob#example.com has 3 mailboxes:
"bob#example.com"
"Example Support"
"Online Archive - bob#example.com"
and the account bob#gmail.com only has 1 mailbox:
"bob#gmail.com"
The screenshot is after [right clicking "Example Support" > Data File Properties... > Advanced]
The mailbox "Example Support"
This is the mailbox I'm interested in. It has the email address "support#example.com".
Find Outlook.Store by it's email address
I know how to find the Outlook.Store object for the mailbox "Example Support", given only it's email address:
Function GetStore(oApp As Outlook.Application, emailAddress As String) As Outlook.Store
Dim oStore As Outlook.Store
Set oStore = Nothing
Dim s As Outlook.Store
For Each s In oApp.Session.Stores
If s.ExchangeStoreType = olExchangeMailbox Then
Dim PR_MAILBOX_OWNER_ENTRYID As String
PR_MAILBOX_OWNER_ENTRYID = "http://schemas.microsoft.com/mapi/proptag/0x661B0102"
Dim ownerEntryId As String
ownerEntryId = s.PropertyAccessor.BinaryToString(s.PropertyAccessor.GetProperty(PR_MAILBOX_OWNER_ENTRYID))
Dim oAddressEntry As Outlook.AddressEntry
Set oAddressEntry = oApp.Session.GetAddressEntryFromID(ownerEntryId)
Dim oExhangeUser As Outlook.ExchangeUser
Set oExhangeUser = oAddressEntry.GetExchangeUser()
If oExhangeUser.PrimarySmtpAddress = emailAddress Then
Set oStore = s
Exit For
End If
End If
Next s
Set GetStore = oStore
End Function
Question
How do i find the Outlook.Account object of a mailbox, given only the email address of that mailbox?
Details
I can see the Outlook.Account object with .SmtpAddress "bob#example.com" that i want, in the debugger. But, i can't find any relation between it and the mailbox for "Example Support", unlike in the screenshot.
The Outlook.Store object for the mailbox "Example Support", is not the .DeliveryStore for the Outlook.Account object with .SmtpAddress "bob#example.com".
Essentially, you need to find PR_SERVICE_UID of the profile section where the store account properties are stored. Once you have that, you can look through all accounts (IOlkAccountManager) and check if you can find a matching IOlkAccount object with the same value of the PROP_MAPI_SERVICE_UID property. You can see these (and other) objects in OutlookSpy.
You can do that in C++ or Delphi, but not in VBA or VB6 since it requires Extended MAPI.
If using Redemption (I am its author) is an option, it exposes the IRDOStore.StoreAccount property. You can also start with an RDOAccount object (exposed in the RDOSession.Accounts collection), cast it to RDOExchangeAccount, and loop through the IRDOExchangeAccount.AllStores collection.
set oomStore = Application.ActiveExplorer.CurrentFolder.Store
Set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set redStore = Session.GetRDOObjectFromOutlookObject(oomStore)
set redAccount = redStore.StoreAccount
Debug.Print "Store account name: " & redAccount.Name
Debug.Print "All account stores:"
for each otherStore in redAccount.AllStores
Debug.Print otherStore.Name
next
There is no direct correlation between accounts and stores except delivery stores. You even can add a new store to the profile at runtime, see Add or remove a store for more information.
The best what you could do is to try to retrieve a shared store by using the GetSharedDefaultFolder method which returns a Folder object that represents the specified default folder for the specified user. Getting the Parent property value can lead you to the store.
Related
I have an automated powershell script to send alert email. Since the alert are send from a generic email.. i want people replying to the email to goto another email address say efg#outlook.com.
$Outlook = New-Object -comObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "asd#outlook.com"
$Mail.Subject = "Alert Email"
$Mail.HtmlBody = $HTML
$Mail.Headers.Add("In-Reply-To", "<efg#outlook.com>")
$Mail.display()
$Mail.send()
somehow this is not working.
Managed to get it from the below
ReplyRecipientNames
$Mail.ReplyRecipientNames = "efg#outlook.com"
Firstly, MailItem object does not expose the Headers property - your script will stop rigth there.
If you want to redirect replies to a different address, use Mail.ReplyRecipients.Add("efg#outlook.com")
You can use the MailItem.SendUsingAccount property which allows setting up an Account object that represents the account under which the MailItem is to be sent. Be aware, the account should be configured in Outlook in that case. For example, here is a VBA code sample which shows how to set up the property:
Sub SendUsingAccount()
Dim oAccount As Outlook.account
For Each oAccount In Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
Set oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
oMail.Recipients.Add ("someone#example.com")
oMail.Recipients.ResolveAll
Set oMail.SendUsingAccount = oAccount
oMail.Send
End If
Next
End Sub
For Exchange users you may also consider using the MailItem.SentOnBehalfOfName property which is represented by a string indicating the display name for the intended sender of the mail message.
But also you may be interested in the MailItem.ReplyRecipients property which returns a Recipients collection that represents all the reply recipient objects for the Outlook item. The following article which I wrote for the technical blog shows how to deal with a recipient collection, see How To: Fill TO,CC and BCC fields in Outlook programmatically for more information.
I just need to be pointed in the right direction, on how
to send an email using VBA. I have Lotus as an email system which is embedded into our intranet system.
As a try, this code prepares an email and send it via Lotus (installed on pc) :
Dim ns As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim sender, recipient As String
'sender = Forms![LogIn]![TxtEmail]
If (Not IsNull(DLookup("Email", "Users", "UserName ='" & Me.Affectation.Value & "'"))) Then
recipient = DLookup("Email", "Users", "UserName ='" & Me.Affectation.Value & "'")
MsgBox "recipient *" & recipient & "*"
Else
MsgBox " recipient null"
End If
If Not (ns Is Nothing) Then
Call ns.InitializeUsingNotesUserName("CN=MyuserName/O=Cmpany", "password")
Set db = ns.GetDatabase("ServerName", "mail\MyuserName.nsf", False)
If (Not (db Is Nothing)) Then
Set doc = db.CreateDocument()
doc.Form = "Memo"
doc.SendTo = recipient
doc.subject = "Email Subject"
Dim rt As NotesRichTextItem
Set rt = doc.CreateRichTextItem("Body")
rt.AppendText ("Body text")
doc.Send (False)
Set rt = Nothing
Set doc = Nothing
MsgBox "Message Sent."
Else
MsgBox "db Is Nothing"
End If
Set db = Nothing
Set ns = Nothing
Else
MsgBox "ns Is Nothing"
End If
My question here is how set this code to make the target Lotus the one on our intranet: my login is such "39398C#mycompany.com" and the application is accessed by "http://mail.mycompany.com/mail/username.nsf..."
Unfortunately this is not possible this way. This "embedded" Lotus Notes as you call it is a simple website. It is called "iNotes" and does not have any dlls installed on your client (unless you install the ActiveX control for IE, but that does not help anything with your problem).
For sending eMails via iNotes you need a complete new method and you need your Domino administrator to help you with it: You could either use a webservice to send your mail (this has to be enabled on the server) or you can use DIIOP (again: DIIOP- Task has to be loaded on server).
To at least compose an email, you could use the mailto: protocol, but you need to set iNotes to be your mailto- protocol- handler:
Open Internet Explorer browser and log into iNotes (http://mail.mycompany.com/mail/username.nsf). Please note that this option is not available at this time to Firefox browser users.
Click the "Preferences" button located in the top right corner.
Find "Default Mail Client" section on the "Basics" tab of the iNotes preferences.
Click the button "Make Default".
Using this approach you cannot send the mail directly but need the user to press "Send".
I am not sure what you mean by "I have Lotus as an email system which is embedded into our intranet system".
You need the Notes client installed locally to be able to use COM in your own code. Use the ID file (must be local in the Notes Data directory) for your corporate account amd point to the server on the network for your mailfile.
But you can't point your program to a iNotes instance on a web server, it has to be on a Domino server accessed with a Notes client.
What you could do is to create a new web application on the server, where you have an agent that will read HTTP POST data, create an email and send it out.
Then you simply make a HTTP post from your application.
Here are a couple of blog entries I wrote that might help you:
http://blog.texasswede.com/free-code-class-to-read-url-name-value-pairs/
http://blog.texasswede.com/parse-url-in-domino-agent/
You should probably change your code to send mail via SMTP instead of using the Notes API objects. Microsoft provides an object model called CDO that I think will help you. See the answer to theis question for details. You will just need the hostname or IP address information to connect to a Domino server in your infrastructure that supports inbound SMTP.
Not sure about it, because that code is pretty old as we know use Outlook and I haven't use it in a long while, but that might be some insight :
I seem to remember that if you add doc.From = ns.CommonUserName, this will choose your session automatically!
And the full code :
Dim session As Object
Dim db As Object
Dim doc As Object
Dim attachme As Object
Dim EmbedObj As Object
Dim attachment() As String
Dim i As Integer
Set session = CreateObject("notes.notessession")
Set db = session.GetDatabase("", "")
Call db.OPENMAIL
Set doc = db.CreateDocument
With doc
.Form = "Memo"
.sendto = MailDestinataire
'.copyto = MailDestinataire2
.Subject = Sujet
.Body = CorpsMessage
.From = session.CommonUserName
.posteddate = Now
.SaveMessageOnSend = True
End With
I need to write a formula that recognizes when someone's birthday is and trigger www.zapier.com.]
I have a birthday-recognition formula that creates a "send email" hyperlink, but I need it to be automatically sent (and delayed to 10am) non-interactively. I also did something in VBA but I only managed to write code that sends that message to 1 person.
Here's the working birthday-recognition formula. Client names are in column C8:C100, emails are in D8:D100, DOBs are in E8:E100 and the "send mail" hyperlinks are in F:100.
=IF(TEXT(E13;"d.m")=TEXT(TODAY();"d.m");HYPERLINK("mailto:"&D13&"? subject="&$D$2&"&body="&SUBSTITUTE(SUBSTITUTE($E$3;"$";C13);"#";$D$4);"pošalji čestitku");"")
"pošalji čestitku" = send mail (croatian language)
VBA code:
Private Sub CommandButton1_Click()
POŠALJIROĐENDANSKEČESTITKE
End Sub
Public Function POŠALJIROĐENDANSKEČESTITKE()
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = Cells.Range("D8:D1000")
olMail.subject = "Sretan rođendan"
olMail.Body = "Poštovani," & vbCrLf & vbCrLf & "Želimo Vam sretan rođendan"
& vbCrLf & vbCrLf & "Sve najbolje," & vbCrLf & vbCrLf & "svinaweb"
olMail.Send
End Function
This code just sends the message to one email when I click on the command button, but as I said I want it to be sent to every person that has a birthday today and to delay the sending of the emails to 10am instead of midnight.
I am using Excel 2013.
The Recipients property of the MailItem class returns a Recipients collection that represents all the recipients for the Outlook item.
The Recipients class provides the the Add method to create a new Recipient object and add it to the Recipients object. The Type property returns or sets the type of recipient. It can be one of the following OlMailRecipientType constants: olBCC, olCC, olOriginator, or olTo.
So, you can send the single email to all people. You just need to add them to the Recipients collection. Or, if you need to have individual message bodies, you can create separate email messages.
The DeferredDeliveryTime property of the MailItem class allows to set a Date indicating the date and time the mail message is to be delivered.
We have a Document Library set up to accept user administration requests from our managed school districts. I recently made some updates to the form used to enter requests and some minor changes to the agent used to notify our administrators of the new request. Since these changes, the notification emails, which were once being received in rich text with an embedded document link, are now coming in as plain text. I have reverted both the form and the agent to previous versions and email message remains plain text. The agent's code follows.
Option Public
Use "Variables"
Dim db As NotesDatabase
Sub Initialize
On Error Goto gotError
Set s = New NotesSession
Dim doc As NotesDocument
Dim kbaseDb As NotesDatabase
Dim kdoc As NotesDocument
Set db = s.CurrentDatabase
Set doc = s.DocumentContext
Dim fromName As NotesName
Dim commName As String
Set fromName = s.CreateName(doc.from(0))
commName = fromName.Common
Dim memo As New NotesDocument(db)
Dim body As NotesRichTextItem
memo.Form = "Memo"
memo.SendTo = techEmail
memo.Subject = doc.categories(0) + " admin request from " + districtName
If doc.priorityflag(0) = "Priority" Then
memo.Subject = doc.Categories(0) + " PRIORITY admin request from " + districtName
memo.DeliveryPriority = "H"
End If
Set body = memo.Createrichtextitem("Body")
Call body.AppendText("Please process this " + doc.action(0) + " request from " + commName + ".")
Call body.AddNewLine(2)
Call body.AppendText("Comment: " + doc.comment(0))
Call body.AddNewLine(1)
Call body.AddNewLine(1)
Call body.AddNewLine(1)
Call body.AppendText("Link to request ")
Call body.AppendDocLink( doc, "Link to request ")
Call memo.send(False)
Call doc.ReplaceItemValue("OwnerNotified", doc.Owner)
Call doc.Save(True, False)
Exit Sub
gotError:
Print "<b><FONT color=red>System Error (" + Str(Err) + "): " + Error
Exit Sub
End Sub
It seems like it's something to do with the signer of the agent- unless somehow your reversion to the original agent hasn't worked.
Here's a set of things I woudl check :
Identify the person who the agent is running as. It's usually the signer, or web user if it's a web agent and "Run as web user" is ticked on the agent properties.
Check their entry in the NAB. If they have their mail system NOT set to Notes, then the server's email sending settings must come into action when sending on their behalf - check the server document in the NAB, under MTAs .. Message Content field. I believe this tells the server how to send such emails.
If this is the issue, then fixes would be :
* Sign the agent with another Id who uses Notes Mail
* If you can't sign with another Id, set the email system of the signer to Notes Mail
Fingers crossed..
The fix was to change the "Message Content" setting for outbound MIME conversion. This is set to "Convert from Notes to plain text" by default and needed to be changed to "Convert from Notes to HTML".
Details are on this page in the InfoCenter:
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.help.domino.admin.doc%2FDOC%2FH_SPECIFYING_MIME_CONVERSION_OPTIONS_OVER.html
I'm looking for kind of the opposite of creating a rule to auto-forward
emails. I want to create a rule that acts on RECEIVED auto-forwarded emails,
but not any that were manually forwarded or replied to by the same person.
E.g. Jim forwards me all emails with "blah" in the subject, and I want to
move those auto forwards to my "Jim's auto-forwards" folder, but if he
forwards me a message manually that says "blah" but he adds his own comments,
I want it to stay in my inbox.
Outlook seems to know that it is auto forwarded, as it shows up
as such when you view the email. Just above the "From" section but
just below the ribbon, it says something like:
"This message was AutoForwarded."
However I haven't found any option to create a rule filtering these.
Our exchange server (Outlook maybe?) adds the following headers when auto-forwarding:
Auto-Submitted: auto-generated
X-MS-Exchange-Generated-Message-Source: Mailbox Rules Agent
(Visible by opening an email and viewing the message "Properties" to see the headers) These appear to be what Outlook is using to detect that a message was AutoForwarded (or at least coincide)
And Outlook/Exchange 2013 has the filter option "with specified words in the message header"
I have used a rule that looks similar to the following to successfully move only "blah" subject messages autoforwarded from "Jim" to a specific folder:
Apply this rule after the message arrives
from 'jim#example.com'
and with 'blah' or 'blurg' in the subject
and with 'auto-generated' or 'Auto-Submitted' in the message heade
move it to the 'Jims auto-forwards' folder
And this has appeared to prevent any that he's manually forwarded from being processed by the same rule.
Our Exchange Server adds the following header for Auto Forwarded and Auto Replies
X-MS-Exchange-Inbox-Rules-Loop: abc#company.com
where abc#company.com is the email of the person auto forwarding the email.
I use MS Outlook 2010 in which i have setup a rule ->
From: abc#company.com
and with 'X-MS-Exchange-Inbox-Rules-Loop: abc.xyz#company.com'
or 'X-MS-Exchange-Inbox-Rules-Loop: abc.XYZ#company.com' in the message header
move it to the 'xyz' folder
i have checked abc.xyz#company.com as well as abc.XYZ#company.com in message header as in some auto Fwd/Re email header the Lastname of the sender was uppercase.
Note: as mentioned before this rule applies to all Auto Forwarded and Auto Replies (e.g Out of office/ vacation auto replies) from that person. Manual Fwd/RE emails are not filtered
I do not think rules can do this.
Try some VBA. untested
Edit 2013 02 26
Put the code in ThisOutlookSession http://www.slipstick.com/outlook-developer/how-to-use-outlooks-vba-editor/
Here are some references so you can debug if necessary.
NewMailEx: http://msdn.microsoft.com/en-us/library/office/bb147646(v=office.12).aspx
AutoForwarded Property: http://msdn.microsoft.com/en-us/library/office/ff867162.aspx
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim varEntryIDs
Dim objItem
Dim i As Integer
Dim myOlApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
varEntryIDs = Split(EntryIDCollection, ",")
For i = 0 To UBound(varEntryIDs)
Set objItem = Application.Session.GetItemFromID(varEntryIDs(i))
'Debug.Print "NewMailEx " & objItem.Subject
If objItem.SenderName = "Jim Smith" Then
If objItem.AutoForwarded then
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
' Assumes destination folder is directly under the Inbox
Set myDestFolder = myInbox.Folders("Jim AutoForwarded")
objItem.Move myDestFolder
End If
End If
Next
Set objItem = Nothing
Set myDestFolder = Nothing
Set myInbox = Nothing
Set myNameSpace = Nothing
End Sub