Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SendUsingAccount (2007)

    I'm trying to automatically send out emails from an account that is not the default account. I've discovered the expression "SendUsingAccount" is new to Outlook 2007 and is designed for this.

    However, I'm having trouble figuring out how to get everything set up for it.

    I've checked online and I'm finding examples of code that do not work, and any suggestions for help are basically suggesting a Google search. It's an endless loop.

    Anyone here familiar with it?

    I've tried to piece together some code to work, but I haven't had any luck at all. I know the below example does not work, but it's about all I can find to get started with.


    Sub mailtest()
    Dim OutApp As Object
    Dim OutNS As Object
    Dim OutAcct As Object
    Dim oAccount As Outlook.Account
    Dim OutMail As Object
    Dim EmailName As String
    EmailName = "name@dckdje.com"

    Set OutApp = CreateObject("Outlook.Application")
    Set OutNS = OutApp.GetNamespace("MAPI")
    OutNS.Logon
    Set OutAcct = OutNS.Accounts
    Set oAccount = Application.Session.Accounts

    Dim oMail As Outlook.MailItem
    Set oMail = Application.CreateItem(olMailItem)
    oMail.Subject = "Subject"
    oMail.Recipients.Add EmailName
    oMail.Recipients.ResolveAll
    oMail.SendUsingAccount = oAccount (1)
    oMail.Send

    End Sub


    I sure do appreciate any assistance!

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: SendUsingAccount (2007)

    It's always helpful if you explain what is erroring out. The code above has some redundancies, but the main problem I see is that according to http://msdn.microsoft.com/en-us/library/bb208225.aspx there is no "Outlook.Account" object - it should be "Outlook.Accounts" Collection. I don't have 2007, but see if this simplified version works:

    Option Explicit

    Sub mailtest()
    Dim oAccount As Outlook.Accounts
    Dim oMail As Outlook.MailItem

    Set oAccount = Application.Session.Accounts
    Set oMail = Application.CreateItem(olMailItem)
    oMail.Subject = "Subject"
    oMail.Recipients.Add "name@dckdje.com"
    oMail.Recipients.ResolveAll
    oMail.SendUsingAccount = oAccount(1)
    oMail.Save
    oMail.Send

    Set oMail = Nothing
    Set oAccount = Nothing
    End Sub

    And post back the error messages you get.
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,572
    Thanks
    5
    Thanked 1,057 Times in 926 Posts

    Re: SendUsingAccount (2007)

    Joe

  4. #4
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SendUsingAccount (2007)

    Hi,

    Thanks for pointing me in the right direction. I haven't had time to get back into it, but I will check it out when I have time. I did see the referenced link and it was confusing to me (not real strong with VBA yet). I'll spend some more time sifting through it and see if I can figure things out.

    I sure appreciate the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •