none
Default Send Account, Access 2010 RRS feed

  • Question

  • Hi all,

    I've recently switched from WLM to Outlook 2010 (32 bit), and am wondering how I can designate a default account to send mail from.

    Here at work I have three work accounts and one personal account, and by default whatever account folder I happen to have highlighted is the one that is used to send from.  This has caused some amount of embarrasement on my part, and I'd much like to have ALL sent items default to a single account, regardless of the active folder.

    Can someone advise if this can be done please?  I've searched options and have not seen much, and under Account Settings, my would-be default account is set as default (and even says "sedn from this account by default"), yet in practice it doesn't seem to honor that.

    Thanks in advance,


    Jack D. Leach (Access MVP)
    UtterAccess Wiki: (Articles, Functions, Classes, VB7 API Declarations and more)

    Tuesday, March 6, 2012 7:26 PM

Answers

  • The easy way is to monitor the Inspectors.NewInspector event, and get MailItem from Inspector.CurrentItem (make sure to check for e-mails only though, and not other item types).  You still need to get the Inspectors collection from Application.Inspectors during Application_Startup though.  If your code isn't running at all check your macro security.  I think MsgBox calls fail during startup, but adding a Stop statement should work.

    However, once your code is working, and if you keep that item open and open another item, you'll lose the reference to the previous MailItem object.  In that case you need to implement Inspector Wrappers to handle it perfectly:

    Developing an Inspector Wrapper for Outlook 2010:
    http://msdn.microsoft.com/en-us/library/ff973716.aspx


    Eric Legault
    MVP (Outlook)
    About me...

    • Marked as answer by Jack D Leach Tuesday, March 6, 2012 9:52 PM
    Tuesday, March 6, 2012 9:37 PM
    Moderator

All replies

  • Outlook does honor the default "send using account" if the folder you are in is in a data store not related to an account; otherwise it'll use the sending account for the related account.

    If you want to change this in code (this IS a programming forum) on an item-by-item basis, set the MailItem.SendUsingAccount property.


    Eric Legault
    MVP (Outlook)
    About me...

    Tuesday, March 6, 2012 8:10 PM
    Moderator
  • Do you happen to have an example of how I can obtain a reference to the MailItem every time a window is opened?  I'm looking at the NewInspector event, or maybe the MailItem_Open event, though I seem to be having some trouble trying to catch the actual events.

    Even Application_Startup, a simple messagebox isn't displaying when I open Outlook...  am I missing a setting somewhere to enable code?  I'm working in ThisOutlookSession, but it appears as though no code is running

    Thanks,


    Jack D. Leach (Access MVP)
    UtterAccess Wiki: (Articles, Functions, Classes, VB7 API Declarations and more)


    Tuesday, March 6, 2012 9:27 PM
  • The easy way is to monitor the Inspectors.NewInspector event, and get MailItem from Inspector.CurrentItem (make sure to check for e-mails only though, and not other item types).  You still need to get the Inspectors collection from Application.Inspectors during Application_Startup though.  If your code isn't running at all check your macro security.  I think MsgBox calls fail during startup, but adding a Stop statement should work.

    However, once your code is working, and if you keep that item open and open another item, you'll lose the reference to the previous MailItem object.  In that case you need to implement Inspector Wrappers to handle it perfectly:

    Developing an Inspector Wrapper for Outlook 2010:
    http://msdn.microsoft.com/en-us/library/ff973716.aspx


    Eric Legault
    MVP (Outlook)
    About me...

    • Marked as answer by Jack D Leach Tuesday, March 6, 2012 9:52 PM
    Tuesday, March 6, 2012 9:37 PM
    Moderator
  • I think I shouldn't need a reference past the opening anyway, I only want to set it when the window opens, I want to have the option to manually change afterwards (is the MailItem.SendUsingAccount writeable from the NewInspector event?  I'll test...)

    I'll try Stop and verify the code actually is running.

    Thanks for the help,


    Jack D. Leach (Access MVP)
    UtterAccess Wiki: (Articles, Functions, Classes, VB7 API Declarations and more)

    Tuesday, March 6, 2012 9:52 PM
  • Some properties and methods aren't available until the first Inspector.Activate event is called.  You should add your code to the MailItem.Open event anyway.

    Eric Legault
    MVP (Outlook)
    About me...

    Tuesday, March 6, 2012 9:54 PM
    Moderator
  • Hi Eric,

    Hopefully just one last thing to wrap up.  I've got the MailItem_Open event setting the SendUsingAccount, that's working well, except it applies that account to new, blank emails as well as replies and fowards.  For replies and fowards, I would like to disregard the custom default and instead use the previously used account for the mailitem.

    I've been able to discern a reply from a new email or a forward email by checking the Recipients.Count, but this still leaves Forwarding as an open end.  Is there some MailItem property that identifies the MailItem as one that was created via a Forward method?  I'm not seeing much in the object browser to help with that.

    Thanks in advance,


    Jack D. Leach (Access MVP)
    UtterAccess Wiki: (Articles, Functions, Classes, VB7 API Declarations and more)


    • Edited by Jack D Leach Wednesday, March 7, 2012 1:55 AM correct event to MailItem_Open (was Inspector_Activate)
    Wednesday, March 7, 2012 1:24 AM
  • >> I've been able to discern a reply from a new email or a forward email by checking the Recipients.Count, but this still leaves Forwarding as an open end.  Is there some MailItem property that identifies the MailItem as one that was created via a Forward method? <<

    It appears I can check the ConversationIndex, which will be something other than ZLS if it's forwarding. 

    In case anyone else stumbles upon the thread looking for a similar result with similar lack of Outlook coding, here's the working code which will start live testing tomorrow.  Note the workaround for adding a plaintext signature - not the best setup in the world but it'll serve my purpose (likewise the default email constant would ideally be moved out of the module and into some user-accessible setting).

    Option Explicit
    Private WithEvents m_Inspectors As Outlook.Inspectors
    Private WithEvents m_MailItem As Outlook.MailItem
    Const DEFAULT_ACCOUNT = "default@email.com"
    Private Sub Application_Startup()
      Set m_Inspectors = Application.Inspectors
    End Sub
    Private Sub m_Inspectors_NewInspector(ByVal Inspector As Inspector)
      On Error Resume Next
      Set m_MailItem = Inspector.CurrentItem
    End Sub
    Private Sub m_MailItem_Open(Cancel As Boolean)
      If (m_MailItem.Recipients.Count = 0) And (m_MailItem.ConversationIndex = "") Then
        m_MailItem.SendUsingAccount = GetAccount(DEFAULT_ACCOUNT)
        m_MailItem.Body = _
          vbCrLf & _
          vbCrLf & _
          "----------" & vbCrLf & _
          "Jack D. Leach"
      End If
    End Sub
    Public Function GetAccount(DisplayName As String) As Outlook.Account
      Dim acc As Outlook.Account
      For Each acc In Application.Session.Accounts
        If acc.DisplayName = DisplayName Then
          Set GetAccount = acc
          Exit For
        End If
      Next acc
    End Function

    There only thing left I'm a little uncomfortable about is the use of On Error Resume Next in NewInspector (it seems to work, but I'd rather explicitly check the type, though Inspector.Class = olMail doesn't seem to match up?)

    Thanks again for the help, this should do.


    Jack D. Leach (Access MVP)
    UtterAccess Wiki: (Articles, Functions, Classes, VB7 API Declarations and more)

    Wednesday, March 7, 2012 2:13 AM
  • The best way to determine if an e-mail is a reply or forward is to trap the e-mail that's being replied or forwarded to: then trap the Reply, ReplyAll or Forward events.  Granted, this is a little more work because you also have to trap Explorer.SelectionChange and get Explorer.Selection to get the source item.  Otherwise, I can't think of what's uniquely different between a Forward and a Reply AND a blank e-mail.  It could be where the MAPI property PR_MESSAGE_FLAGS (0x0E070003) = 9 (see the PropertyAccessor object for reading MAPI props).

    Checking Inspector.Class gives you olInspector!  Just check Item.Class (don't pass Item to a hard MailItem variable if it's NOT a MailItem), where Item is passed in the argument to the NewInspector event.


    Eric Legault
    MVP (Outlook)
    About me...

    Wednesday, March 7, 2012 3:47 AM
    Moderator