none
Resolving Autoamation Error. RRS feed

  • Question

  • Hi,

    I am not an OUTLOOK programmer but I have had reasonable success in the past with performing some basic Word to OUTLOOK interoperability processes.

    Now I am really stumped.  Here is what I am trying to do:

    1.  User clicks a control in Word that runs a procedure that creates and presents a new OUTLOOK message partially completed for the user.

    2.  The user fills in the recipient field, makes any additional coments an clicks "Send"

    3.  The message and only that message "actually" gets sent and does not remain in the OUTLOOK outbox until at some later point the user decides to send messages.

    Getting success to step 2 has been easy enough.  It is step 3 that is killing me.  I have managed some success and usually the code below will work the first time run if:

    1.  OUTLOOK has been opened, mail sent, and OUTLOOK closed.

    2.  Word has been opened, closed, and then reopened.

    However after running sucessfully, if I try to run the code again I typically get one of the following three errors:

    462 - The remote server machine does not exists or is unavailable

    -2147467259 The operation failed

    -2147023170 Automation Error - The remote procedure call failed.

    with the third listed error occurring most often.  I have not been able to determine why any of these errors occur but the failures occur most often in the SendMessage function.  There must be something not being reset, killed or whatever after a successful run that triggers to the error or there is some timing issue.

    Apreciate any assistance.

    I've tried to comment the code to help you understand what I'm trying to do and I've put some debug statements in to help you see where the code runs to before errors.

    Option Explicit
    Dim m_OutlookApp As Object
    Dim olNS As Outlook.NameSpace
    Sub SendHTMLMessage()
    Dim strTo As String
    Dim strSubject As String
    Dim strBody As String
    Dim strSend As String
      On Error GoTo lbl_Error
      strTo = ""
      strSubject = "MESSAGE TEST"
      strBody = "Test message body.<br>" & _
                "See this link: " & _
                "<A HREF=""Greg">http://gregmaxey.mvps.org//index.html"">Greg Maxey</A>"
      If Mail_From_Outlook_Html(strSubject, strBody) = True Then
        MsgBox "Your mail has been sent."
      End If
    lbl_Exit:
      Exit Sub
    lbl_Error:
      MsgBox Err.Number & " " & Err.Description
      Resume lbl_Exit
    End Sub
    Function Mail_From_Outlook_Html(ByRef strSubj As String, strBodyHtml As String) As Boolean
    'Working in Office 2000-2010
    Dim OutMail As Object
      Set m_OutlookApp = Nothing
      'If OUTLOOK is not running then launch an instance.
      On Error Resume Next
      Set m_OutlookApp = GetObject(, "Outlook.Application")
      On Error GoTo 0
      'Does OUTLOOK exists on the user's machine?
      On Error GoTo Err_Handler
      If m_OutlookApp Is Nothing Then
        Set m_OutlookApp = CreateObject("Outlook.Application")
      End If
      Set olNS = m_OutlookApp.GetNamespace("MAPI")
      olNS.Logon
      Set OutMail = m_OutlookApp.CreateItem(0)
      On Error GoTo 0
      'Build the message
      On Error Resume Next
      With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = strSubj
        .HTMLBody = strBodyHtml & "<br><br>"
        'Display the message so the user can complete the "To" field and make any other changes.
        .Display
      End With
      On Error GoTo 0
      'This could be a Rube Goldberg process, but I need to know did the user click and send message.
      If UserSends = True Then
        'Direct OUTLOOK to send last message.
        If SendMessage = True Then
          Mail_From_Outlook_Html = True
          Set OutMail = Nothing
          Set m_OutlookApp = Nothing
        End If
      Else
        MsgBox "Your message was not sent.", vbInformation + vbOKOnly, "MESSAGE NOT SENT"
      End If
    lbl_Exit:
      Exit Function
    Err_Handler:
      'OUTLOOK could not be created/accessed.
      Mail_From_Outlook_Html = False
      m_OutlookApp.Quit
      Set m_OutlookApp = Nothing
      Resume lbl_Exit
    End Function
    Function UserSends() As Boolean
    Dim j As Long, k As Long
      Set olNS = m_OutlookApp.GetNamespace("MAPI")
      'How many messages are in the outbox?
      j = olNS.GetDefaultFolder(olFolderOutbox).Items.Count
      Debug.Print "Msg count - made it to here"
      'Loop until a message is added to the outbox (i.e., user clicked send)
      Do Until olNS.GetDefaultFolder(olFolderOutbox).Items.Count = j + 1
        DoEvents
        k = olNS.GetDefaultFolder(olFolderOutbox).Items.Count
        DoEvents
      Loop
      UserSends = True
      Debug.Print "UserSends = True"
    Err_ReEntry:
    Cleanup:
      Set m_OutlookApp = Nothing
      Set olNS = Nothing
      Exit Function
    Err_Send:
      MsgBox Err.Number & " " & Err.Description
      UserSends = False
      Resume Err_ReEntry
    End Function

    Function SendMessage() As Boolean
    Dim olItems As Outlook.Items
    Dim olItem As Outlook.MailItem
    Dim olSycs As Outlook.SyncObjects
    Dim olSyc As Outlook.SyncObject
    Dim i As Long
      On Error Resume Next
      Set m_OutlookApp = GetObject(, "Outlook.Application")
      On Error GoTo 0
      On Error GoTo Err_Handler
      If m_OutlookApp Is Nothing Then
        Set m_OutlookApp = CreateObject("Outlook.Application")
        Debug.Print "Create Outlook. Made it to here"
      End If
      Set olNS = m_OutlookApp.GetNamespace("MAPI")
      olNS.Logon
      Debug.Print "Logon Outlook. Made it to here"
      Set olSycs = olNS.SyncObjects
      Debug.Print "Set sycs. Made it to here"
      Set olItems = olNS.GetDefaultFolder(olFolderOutbox).Items
      Debug.Print "Sets items. Made it to here"
      For i = olItems.Count To 1 Step -1
        Set olItem = olItems(i)
        olItem.Send
        'Send last message only
        Exit For
      Next i
      For i = 1 To olSycs.Count
        Set olSyc = olSycs.Item(i)
        If MsgBox("Do you wish to synchronize " & olSyc.Name & "?", vbYesNo) = vbYes Then
          olSyc.Start
        End If
      Next
      SendMessage = True
    Err_ReEntry:
    Cleanup:
      Set olItems = Nothing
      Set olItem = Nothing
      Set olNS = Nothing
      Set olSycs = Nothing
      Set olSyc = Nothing
      Exit Function
    Err_Handler:
      MsgBox Err.Number & " " & Err.Description
      SendMessage = False
      Resume Err_ReEntry
    End Function

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Saturday, March 10, 2012 7:24 PM

All replies

  • Hi Greg,

    Thanks for posting in the MSDN Forum.

    Would you please tell me some questions:

    1. What's mean of <<The message and only that message "actually" gets sent and does not  remain in the OUTLOOK outbox until at some later point the user decides to send messages.>>?  It's based on my undertanding is that the customer will not send the mail immediately. However I feel you code will sent the mail without conside this option.
    2. In sub <<UserSends>>, I found some unused statements. I'm wondering whether you copy the sub from other place and missed something in this issue. Please recheck it.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Sunday, March 11, 2012 2:46 AM
    Moderator
  • Tom,

    The idea is the user is in Word and clicks a button that will create an new OUTLOOK mail message. The user fills in a recipient name and then clicks send.  When they do the message should be "sent" (read send on its way to the recipient) not just sent to the OUTLOOK outbox to sit "unsent."

    I wrote that code myself.  What do you see that isn't used?


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Sunday, March 11, 2012 4:01 AM
  • Hi Greg,

    I never see

    Cleanup:
       Set m_OutlookApp = Nothing
       Set olNS = Nothing
       Exit Function
     Err_Send:
       MsgBox Err.Number & " " & Err.Description
       UserSends = False
       Resume Err_ReEntry
     

    has been used. Would you please clarify it?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 12, 2012 2:26 AM
    Moderator
  • Tom,

    Both run and the Do .... Loop condition is satisfied.

    After OUTLOOK is launched with the SendHTMLMessage procedure, there is no way to dermine (that I know of) if the user just sit there and looks at it, close it without sending a message, or fills in the remaining data and clicks send, other than determine how many messages (if any) are already in the outbox and then loop until there is one more.  When there is, the loop exits.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Monday, March 12, 2012 10:18 AM
  • Do not touch messages in the Outbox - doing so cancels the submission for that message.

    Call MailItem.Send, then SyncObject.Start and make sure Outlook.Application object is still alive so it can finish the sync (which is asynchronous).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Monday, March 12, 2012 4:49 PM
  • Dimitry,

    You lost me.  As I said from the start, I am not an OUTLOOK programer.  How should I revise the code posted?

    Thanks.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Monday, March 12, 2012 4:56 PM
  • Greg,

    Declare Outlook.Application (m_OutlookApp) as a global/clas variable to make sure it stays alive. Do not set it to Nothing.

    Remove all code that accesses accesses the Outbox folder.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Monday, March 12, 2012 6:18 PM
  • Dmitry,

    I have no idea what are are and have been trying to say.  If I remove all access to the Outbox folder then how am I going to detect it the user ever sent the message?


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Monday, March 12, 2012 7:14 PM
  • Why do you need to detect that? The best you can do is to ask Outlook to send it as soon as it can by calling SyncObject.Start or simulating a click on the Send/Receive button.

    Message submission is asynchronous, so it can take Outlook a faily long time to send a message depending on the connection speed and the message size even if Outlook attempts to send the message immediately.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Monday, March 12, 2012 8:58 PM
  • Dmitry,

    Maybe I don't really need to detect that, but the end result I want to achieve is a feeback message back to the user:

    Your messsage has been sent (or even Your message is processed for sending would do.).  It would be a little silly to return that message if the user a) never clicked the send message or went to lunch before clicking the send message or dies before clicking the send message. 

    Again, here is what I am trying to achieve.  If appears impossible and I can accept that.  If is is possible then how:

    1.  From Word or some other office applicton, present the user with an Outlook mail mesage partially completed with a Subject and body.

    2. The message is displayed and the user fills in a recipient (this may be immediately or after lunch).  When the user clicks "Send" this action is detected (I was doing that by monitorin in a loop the count in the OUTLOOK outbox) a boolean flag is set.

    3.  If the flag is true the message is "sent" or the process of sending is initiated.  (Not sit in the OUTLOOK outbox until the user opens OUTLOOK now or at some later time and clicks "Send/Recieve).

    4.  When the send process is intiated the user is alerted "Your message is processed for sending" will be fine.

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Monday, March 12, 2012 9:59 PM
  • That should be easy to do - show the message modally by calling Display(TRUE).

    If the user clicks the Send button, MailItem.Send and Application.ItemSend events will fire.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Monday, March 12, 2012 10:13 PM
  • Dmitry,

    I might be easy to do if I knew how.  Apparently I don't.  Am I not already showing hte message modally?

    With OutMail
        .To = ""
        .CC = ""
    .BCC = ""
        .Subject = strSubj
        .HTMLBody = strBodyHtml & "<br><br>"
        'Display the message so the user can complete the "To" field and make any other changes.
        .Display
      End With


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Monday, March 12, 2012 10:41 PM
  • Off the top of my head:

    Dim With Events OutMail As Outlook.MailItem

    ...

    sub OutMail_Send(byRef Cancel)

      MsgBox "The message was sent"

    End sub

    ...

    With OutMail
        .To = ""
        .CC = ""
    .BCC = ""
        .Subject = strSubj
        .HTMLBody = strBodyHtml & "<br><br>"
        'Display the message so the user can complete the "To" field and make any other changes.
        .Display(TRUE)
      End With


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Monday, March 12, 2012 10:46 PM
  • Dim WithEvents OutMail As Outlook.MailItem

    Compile error vallid only in object module.   Is sounds like you are proposing creating a Class module for the mail item.  That might work, but your little snippets and suggestions are really not getting me any closer to the solution because I have no idea how to properly implement them.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Monday, March 12, 2012 10:56 PM
  • Hi Greg,

    This is a simple sample, I just created it in Word:

    Class1:

    Option Explicit
    
    Private OlApp As Outlook.Application
    Private WithEvents Mail As Outlook.MailItem
    
    Public Sub SendMail()
        Dim recipients As Outlook.recipients
        
        Set OlApp = New Outlook.Application
            
        Set Mail = OlApp.CreateItem(olMailItem)
        Mail.Subject = "Test Mail"
        Set recipients = Mail.recipients
        recipients.Add ("******@******.com")
        recipients.ResolveAll
        Mail.Send
        
        Set Mail = Nothing
        Set OlApp = Nothing
    End Sub
    
    Private Sub Mail_Send(Cancel As Boolean)
        MsgBox Mail.Subject & "has been sent"
    End Sub

    I called it in the module:

    Module1:

    Sub test()
        Dim cls As Class1
        
        Set cls = New Class1
        cls.SendMail
    End Sub

    Please don't forget add reference of Outlook Library.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, March 13, 2012 2:50 AM
    Moderator
  • Tom,

    Thanks for the code and it works for what it does, but it doesn't do what I want to do.  I don't know (in code) who the recipient will be.  I need to .Display the message template and let the user pick a recipient and let the user physically click the "Send" button.  Then I want the message to be "sent' when they do.  Not simply sent to the Outlook outbox.

    When I run the following code (modified from your example) it works to a point.  The point where it doesn't work is the message is not actually "sent."  The code runs without error.  But after it runs, I open Outlook and the message is still sitting in the outbox.  I want the code to actually send the message (sync folders or whatever the correct term is) (e.g., actually be sent on its way to the recipient.

    Option Explicit
    Private OlApp As Outlook.Application
    Private WithEvents Mail As Outlook.MailItem
    Public Sub SendMail()
    Dim recipients As Outlook.recipients
    Set OlApp = New Outlook.Application
    Set Mail = OlApp.CreateItem(olMailItem)
      Mail.Subject = "Test Mail"
      Mail.HTMLBody = "See: " & _
                        "<A HREF=""Greg">http://gregmaxey.mvps.org//index.html"">Greg Maxey</A>""Test, test"
      Mail.Display (True)
      Set Mail = Nothing
      Set OlApp = Nothing
    End Sub
    Private Sub Mail_Send(Cancel As Boolean)
    Dim olNS As NameSpace
    Dim olSycs As SyncObjects
    Dim olSyc As SyncObject
    Dim i As Long
      Set olNS = OlApp.GetNamespace("MAPI")
      olNS.Logon
      Set olSycs = olNS.SyncObjects
      For i = 1 To olSycs.Count
        Set olSyc = olSycs.Item(i)
        olSyc.Start
      Next
    End Sub


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Tuesday, March 13, 2012 3:20 AM
  • Tom, Dmitry,

    EUREKA!!  Some progress.  Modifying Tom's last procedure as shown seems to do the trick. Still proofing.

    Option Explicit
    Public bMailWasSent As Boolean
    Sub CreateAndSendMessage()
     bMailWasSent = False
     Dim cls As clsMyMailer
     Set cls = New clsMyMailer
     cls.SendMail
     If bMailWasSent Then
       Set cls = New clsMyMailer
       cls.TransmitMailInOutbox
       Beep
       MsgBox "Mail was sent"
     Else
       MsgBox "Mail not sent"
     End If
    End Sub

    Private OlApp As Outlook.Application
    Private WithEvents oMailItem As Outlook.MailItem
    Public Sub SendMail()
    Set OlApp = New Outlook.Application
    Set oMailItem = OlApp.CreateItem(olMailItem)
      oMailItem.Subject = "Test Mail"
      oMailItem.HTMLBody = "See: " & _
                           "<A HREF=""Greg">http://gregmaxey.mvps.org//index.html"">Greg Maxey</A>""Test, test"
      oMailItem.Display (True)
      Set oMailItem = Nothing
      Set OlApp = Nothing
    End Sub
    Private Sub Mail_Send(Cancel As Boolean)
     'User clicks send button to send mail.
      bMailWasSent = True
    End Sub
    Public Sub TransmitMailInOutbox()
    Dim olNS As NameSpace
      Set OlApp = New Outlook.Application
      Set olNS = OlApp.GetNamespace("MAPI")
      olNS.Logon
      olNS.SendAndReceive (False)
      Set OlApp = Nothing
      Set olNS = Nothing
    End Sub

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Tuesday, March 13, 2012 3:55 AM
  • Hi Greg,

    I think we aren't able to set Cancel parameter of the Mail_Send sub to True if you want your mail to be sent. Try to comment that line and run you code again.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, March 14, 2012 1:53 AM
    Moderator
  • Tom,

    You lost me.  The last code I posted is working fine for what I want it to do.  I wish it would simply send the mail the first time around, but it doesn't.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Wednesday, March 14, 2012 2:47 AM
  • No, you just need to add Outlook to your project references so that you can use early binding and handle events.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Wednesday, March 14, 2012 6:54 AM
  • Hi Greg,

    Do you add Outlook to your project references?

    @Dmitry,

    Thanks for your great work.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, March 15, 2012 2:53 AM
    Moderator
  • Yes I did.

    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Thursday, March 15, 2012 3:17 AM
  • Hi Greg,

    According to you description, I write the following VBA code to address your goal. It works fine on my side. I recommend you try it and extend it as your wish.

    Module1:

    Sub test()
        Dim flag As Boolean
        Dim c As Class1
        
        Set c = New Class1
        c.SendMail
        flag = c.GetStatu
        If flag Then
            MsgBox "Mail has been sent"
        Else
            MsgBox "Mail hasn't been sent"
        End If
    End Sub
    

     Class1:

    Private OlApp As Outlook.Application
    Private WithEvents OlMail As Outlook.MailItem
    Private cFlag As Boolean
    
    
    Private Sub Class_Initialize()
        cFlag = False
        If OlApp Is Nothing Then
            Set OlApp = New Outlook.Application
        End If
    End Sub
    
    Private Sub Class_Terminate()
        Set OlApp = Nothing
        Set OlMail = Nothing
    End Sub
    
    Private Sub OlMail_Send(Cancel As Boolean)
        cFlag = True
    End Sub
    
    Public Sub SendMail()
        Set OlMail = OlApp.CreateItem(olMailItem)
        OlMail.Display (True)
    End Sub
    
    Public Function GetStatu() As Boolean
        GetStatu = cFlag
    End Function
    

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 16, 2012 5:50 AM
    Moderator
  • Tom,

    This works for what it does, but it doesn't do what I want.  Using your code, the end result (after the procecure runs) is the e-mail "reported as sent," is still sitting in my Outlook outbox.  When I open Outlook, there it sits.  I have to sent and recieve, or close Outlook which sends and receives.

    The code I posted earlier in the message beginning with "EUREKA" does what I want, I just don't understand why your method won't or why in my method I have to initiate Outlook twice as I have.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Friday, March 16, 2012 10:06 AM
  • Hi Greg,

    What's type of your Outlook account? Is it a Exchange account? I run my VBA project under my Exchange account, it works fine on my side and no email will be left in Outbox. It will be sent timely.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 19, 2012 4:53 AM
    Moderator
  • Tom,

    I have no idea.  It is just OUTLOOK 2010 out of the box installed on my home stand alone PC.  Maybe it is because I am calling OUTLOOK from Word.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Monday, March 19, 2012 10:34 AM
  • Hi Greg,

    I also do it from Word, it works fine. I think you need clarify the mean of "It is just OUTLOOK 2010 out of the box installed on my home stand alone PC."

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, March 20, 2012 4:35 AM
    Moderator
  • Greg, as you can see, this is a not as simple a scenario as it seems. A couple of points:

    1. While Dmitry's suggestion of using a modal window can be useful, modal message windows can also cause problems for other Outlook add-ins, so we generally recommend avoiding them if at all possible.

    2. What is the real-world scenario here in terms of who will be using this solution? Every type of mail account (Exchange, POP, IMAP, HTTP) can behave a bit differently in this scenario, so Tom's question about e-mail account type is relevant and should not be taken lightly. If you are planning to deploy this to various customers who may have different account types set up, you would really need to make sure it works in all scenarios.

    3. Overall, automating Outlook when it's not running can be problematic in some scenarios. It sounds like this is something you want to support. If so, be sure to first get a reference to any default folder such as the Inbox folder using Set oInbox = olNS.GetDefaultFolder(olFolderInbox). Trust me on this :)

    4. You really want to implement the ItemSend event. That will fire when the item starts to be sent. In there, you can interrogate the message to learn about it. If your solution is setting something specific in the body or subject, then your code can check to see if it's one of  "your" messages.

    5. As far as the send/receive goes, the SyncObjects collections is the way to determine when a Send/Receive starts and ends.

    Overall, these are the key pieces you need to use, but it's important to note that the Outlook object library is not like the Word object library. In Word, the object model has you basically working with everything "live" since there is more or less a 1-1 correlation between the Word user interface and the object model. In Outlook, that's not the case since Outlook is built on top of MAPI and has some other architectural concerns. So seemingly simple things like that can be a lot more challenging then they would appear on the surface.


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Monday, March 26, 2012 9:01 PM
    Moderator
  • Bill,

    Thanks for your reply.  Your last statement about things being a lot more challenging rings true.  I've had to shelve the project for now because I don't have time to figure out all of the issues. 

    Basically I was trying to create a control on a Word ribbon that if clicked would open the users default e-mail account and send a "Tell a Friend" type of message to anyone they then chose to enter in the "To:" field.  I've got it working on my end (my PC), but as you say, not every e-mail account is alike.

    I'll get back to it when I find the time and if I have more question, I'll ask.

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Monday, March 26, 2012 9:30 PM
  • for very simple things like opening new mail to send and let user take over from here, consider simpy executing shell command passing "mailto:" address type.
    Tuesday, March 27, 2012 8:27 AM
  • DamianD,

    I've basically done that.  However, in testing with my own systems (I use OUTLOOK) as my mail program, that method leaves the messages unsent in my OUTLOOK outbox.  I have to open OUTLOOK then Sent/Recieve.

    So what I did was:

    Is OUTLOOK the mail handler?

    Yes, then do it like I've described above.

    No, then excute shell command and hope whatever mail program the user is using actually sends the mail.

    Thanks


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Tuesday, March 27, 2012 11:14 PM
  • i guess you could try mixed approach - simply start outlook in background and use mailto to present mail to user. When user click 'send' it will be actually sent because outlook was started by you. Simply monitor SyncObjects collection to know if your mail was sent and close outlook afterwards.
    Wednesday, March 28, 2012 8:00 AM
  • SyncObjects will tell you when a sync started by you finishes, there's no way to tell when an automatic sync started by Outlook has finished.
     
    The mailto: protocol actually uses Simple MAPI and invokes the Simple MAPI handler. That might be Outlook, it might be WLM or anything else. To ensure that Outlook handles the mail Outlook automation is the best way to go.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "DamianD" <=?utf-8?B?RGFtaWFuRA==?=> wrote in message news:028afc2a-c51d-49d6-b929-f3bb132e418a...
    i guess you could try mixed approach - simply start outlook in background and use mailto to present mail to user. When user click 'send' it will be actually sent because outlook was started by you. Simply monitor SyncObjects collection to know if your mail was sent and close outlook afterwards.

    Ken Slovak MVP - Outlook
    Wednesday, March 28, 2012 2:14 PM
    Moderator
  • checking periodically if there are still items in SyncObjects will not work?
    Wednesday, March 28, 2012 2:30 PM
  • SyncObjects is a static collection, it is not a list of the *active* syncs.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Wednesday, March 28, 2012 2:33 PM
  • No. That collection is all of the send/receive groups that are set up. It doesn't hold a dynamic list of items to send.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "DamianD" <=?utf-8?B?RGFtaWFuRA==?=> wrote in message news:70a70e14-5dfd-4bc4-bab3-6e1ed3bfe2dc...
    checking periodically if there are still items in SyncObjects will not work?

    Ken Slovak MVP - Outlook
    Wednesday, March 28, 2012 2:34 PM
    Moderator
  • thanks for explanation. So assuming that outlook will handle message, monitoring Sent Items folder should work?
    Wednesday, March 28, 2012 3:00 PM
  • Assuming the item didn't have DeleteAfterSubmit set, yes, monitoring Sent Items would work.
     
    If you call to start a sync yourself you can always tell when it finishes. It's only the send/receives that Outlook does on its own that you can't detect in any way. For your own call you'd just handle the SyncObject.SyncEnd() event for the SyncObject you called Start() on.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "DamianD" <=?utf-8?B?RGFtaWFuRA==?=> wrote in message news:40cf75ce-d58f-4b57-b939-e845e45bc410...
    thanks for explanation. So assuming that outlook will handle message, monitoring Sent Items folder should work?

    Ken Slovak MVP - Outlook
    Wednesday, March 28, 2012 3:37 PM
    Moderator
  • Actually even if Outlook initiates the sync, you will still get SyncObject events - you can see that in OutlookSpy - click Namespace, double click on the SyncObjets collection, go to the EnumVariant tab, open the "All Accounts" sync object, go to the Events tab and wait for Outlook to start a sync.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!


    Wednesday, March 28, 2012 3:49 PM
  • That's new then. We never used to get that event for Outlook initiated synchs. I'll have to check it out.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Dmitry Streblechenko _MVP_" <=?utf-8?B?RG1pdHJ5IFN0cmVibGVjaGVua28gX01WUF8=?=> wrote in message news:fe70d0ab-e32f-407f-bc30-f2226dbf3a4c...

    Actually even if Outlook initiates the sync, you will still get SyncObject events - you can see that in OutlookSpy - click Namespace, double click on the SyncObjets collection, go to the EnumVariant tab, open the "All Accounts" sync object, go to the Evenst tab and wait for Outlook to start a sync.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!


    Ken Slovak MVP - Outlook
    Wednesday, March 28, 2012 5:16 PM
    Moderator
  • It always worked that way in Outlook 2010, and I am pretty sure it is the same in Outlook 2007.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Wednesday, March 28, 2012 6:28 PM
  • It even worked here on OL11 when I tried it. I'm pretty sure that Randy (or maybe Ryan) had told us we couldn't trap OL initiated syncs sometime or other, but I'm glad that's not the case. It's something that can come in handy at times.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Dmitry Streblechenko _MVP_" <=?utf-8?B?RG1pdHJ5IFN0cmVibGVjaGVua28gX01WUF8=?=> wrote in message news:0ecf51e5-1d93-4f12-810d-84db3a24e72d...

    It always worked that way in Outlook 2010, and I am pretty sure it is the same in Outlook 2007.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!


    Ken Slovak MVP - Outlook
    Wednesday, March 28, 2012 6:31 PM
    Moderator
  • Sorry for coming in late, but yes, originally the SyncObject events only fired for code-started syncs. This was changed one or two versions later, but I'm not sure offhand if that was in Outlook 2002 or 2003.

    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Thursday, March 29, 2012 4:27 PM
    Moderator
  • Thanks, Bill. I tested on Outlook 2003 and it works, I didn't bother going back to a 2002 VM to see if it does there too.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Bill Ja - MSFT" <=?utf-8?B?QmlsbCBKYSAtIE1TRlQ=?=> wrote in message news:1399d179-b1e1-4879-a467-181d05215118...
    Sorry for coming in late, but yes, originally the SyncObject events only fired for code-started syncs. This was changed one or two versions later, but I'm not sure offhand if that was in Outlook 2002 or 2003.

    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging


    Ken Slovak MVP - Outlook
    Thursday, March 29, 2012 5:35 PM
    Moderator