none
Outlook Interop problems when using Send() RRS feed

  • Question

  • Hello,

    we have some problems when we try to send a very simple mail via Outook-Interop.
    For example here is a very small program which we use to reproduce the problem.

    Public Class Form1
        Private oOutlook As New Microsoft.Office.Interop.Outlook.Application
        Private oMail As Microsoft.Office.Interop.Outlook.MailItem
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            oMail = oOutlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
    
            Dim oRecip As Microsoft.Office.Interop.Outlook.Recipient = oMail.Recipients.Add(TextBox_An.Text)
            oRecip.Type = Microsoft.Office.Interop.Outlook.OlMailRecipientType.olTo
    
            oMail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatPlain
            oMail.Body = TextBox_Text.Text
            oMail.Subject = TextBox_Betreff.Text
            oMail.Send()
        End Sub
    End Class

    If we now try to send the mail, we produce an exception with the following message.

    "Outlook does not know at least one name" (Hope the translation is correct...)

    The mysterious is, the error happens not with every mail-adress and not with every mailbox. If I try to send the mail with the exact parameters with my own mailbox, it works fine. It also figured out, that there is a outlook contact with this mail adress. If I delete this contact, it works again.

    The contact is generated with an tool. I can use the Tool to generate the exact contact in my own mailbox but the problem still not occurs.

    I'm also not able to Resolve() the recipient before the error occurs, but I don't know why.

    Is there something I can do to make sure that the correct mailadress is accepted?

    Monday, July 2, 2012 8:13 AM

Answers

  • We found a "solution".

    If we change a option to

    - Adressbook, Extras, Options -> Start with contact folder (The second option from the top)

    Outlook is going to send the mail without any errors.

    Friday, September 7, 2012 9:23 AM

All replies

  • Do you only pass only the recipient's name or also the address?

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

    Monday, July 2, 2012 2:44 PM
  • Only the adress. For example john.doe@acme.com
    Monday, July 2, 2012 2:46 PM
  • Hi,

    Can you please give an example for specific "bad" addresses.
    Even better - input of the TextBox_An.Text?

    Also - what happen if you create (manually) an email, type this address there, and try to send?

    Moshe

    Monday, July 2, 2012 5:03 PM
  • Hi,

    Example: a.schaefer@work4all.de

    If we try to send the mail manually in Outlook it works without any problems.

    Wednesday, July 4, 2012 7:48 AM
  • show us code how do you instantiate and initialize outlook variable
    Wednesday, July 4, 2012 11:54 AM
  • The whole code is in my first post...
    Wednesday, July 4, 2012 12:04 PM
  • if that is whole code then maybe try to add following to the top of your button click routine:

    oOutlook.GetNamespace("MAPI").Logon()

    Wednesday, July 4, 2012 2:49 PM
  • If the namespace object gets garbage collected before you are done, the logon won't do anything.

    After creating an instance of the Outlook.Application object, retrieve the Namespace object from oOutlook.GetNamespace("MAPI"), store it in a class variable (along with oOutlook) to make sure it stays alive, then call Logon.


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

    Wednesday, July 4, 2012 4:04 PM
  • In our main application, we store the Namespace along the application lifetime an use Logon(). This is just a very small test application to reproduce the error.
    But I also tried to use Logon() in the test application. Still the same problem. In 99% of all cases we have no problems to send the mail. There a just a handful of addresses which produces the error.

    The exact error message

    System.Runtime.InteropServices.COMException (0x80004005): Outlook kennt mindestens einen Namen nicht. 
       bei Microsoft.Office.Interop.Outlook._MailItem.Send()
    
    Message translation: Outlook does not know at least one name.

    Thursday, July 5, 2012 8:02 AM
  • the same error happens when you call resolve on that recipient? i know that you already wrote about resolve in first mail, but i did not understand explanation what is really happening then.
    Thursday, July 5, 2012 8:56 AM
  • Hi,

    Thanks for posting in the MSDN Forum.

    Based on my experience I would suggest you check if the addresses of contact list in your Outlook are all correct. In my opinion, the exception occurs as a result of the inaccurate address.

    Best Regards,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, July 10, 2012 1:59 AM
    Moderator
  • Hello,

    I can call Resolve() without any errors but the Resolved property is still false after call.

    @Leo_Gao, thanks for the hint. What can I do to check the correctness of the addresses? Till today I thought an e-mail adress can be correct or not :)

    Tuesday, July 10, 2012 7:17 AM
  • All instances of outlook objects are still set to an instance while the error occures.

    Thursday, July 12, 2012 9:16 AM
  • If instead of calling Send you call Save, then open the saved message in Outlook and send it, does it work?


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

    Friday, July 13, 2012 6:37 PM
  • Sascha,

    After reviewing this thread, it seems to me the key piece of information is that this works again after removing the contact that has this SMTP address, so I would focus on that. Is it possible the users with the problem modified it in some way after it was created using the tool? You can check the modified date on these items to check that out.

    Also, this could also be related to the nickname cache, so I'd be curious if you cleared that whether that would also make it work. See http://support.microsoft.com/kb/287623.

    Bill Jacob


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Monday, July 16, 2012 5:35 PM
    Moderator
  • Could there be a character encoding issue? A subtle swap with a similar-looking Unicode character, or an accented character, or similar?

    -Brian

    Monday, July 16, 2012 7:28 PM
  • Hello Bill,

    this sounds logical. So my colleague who has the problem by itself is now on a vacation, so for the next 2 weeks it is not possible for me to reproduce the problem. But I will test this fix as soon as it is possible.

    Sascha

    Tuesday, July 31, 2012 8:40 AM
  • Hi Sascha,

    Did you have any update on this issue?


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Wednesday, August 22, 2012 9:17 PM
    Moderator
  • Hello together,

    now I have some news on this issue.
    The trigger for the problem is to use more then 1 exchange account on your system.
    After you have a second account added and have a contact with the mail-address in your main account, the error occurs.

    Now I can reproduce the problem on my develop environment. I also has tried to,

     - use Save() before Send()
     - Set the SendUsingAccount property to the account who wants to send the mail.
     - clearing the nickname cache as written in the link posted by Bill.

    ... but nothing helps.

    Friday, September 7, 2012 7:35 AM
  • We found a "solution".

    If we change a option to

    - Adressbook, Extras, Options -> Start with contact folder (The second option from the top)

    Outlook is going to send the mail without any errors.

    Friday, September 7, 2012 9:23 AM
  • Hi Sascha,

    That's great, I'm glad you found the key thing to make this happen consistently, and also a workaround. But I'm curious about whether this may be a bug in the object model. Since you can reproduce this consistently now, did you see if the recipient resolves just by using Outlook itself? In other words, is there any difference between the object model and the behavior you see in Outlook itself?


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Friday, September 7, 2012 5:29 PM
    Moderator
  • Hi Bill,

    We could still send mails to everybody by using Outlook itself. Only when we used the outlook object model we had this problems. So I think there is a bug in the object model when using multiple exchange accounts. Hope the information helps.

    Monday, September 10, 2012 7:09 AM