locked
Outlook 365 returns "Sorry, something went wrong. You may want to try again" on Outlook.MailItem.Send() RRS feed

  • Question

  • Hi,

    I'm using Visual Studio 2019 to build a small test program written in VB.Net. This program used until now PIA-references (Microsoft.Office.Interop.Outlook) to show up the outlook mail window using Display() or to send an email directly by using Send().

    Everything worked like a charm with Outlook 2013, 2016, 2019 for both 32bit and 64bit versions.

    Now, with Outlook for Microsoft 365 MSO (16.0.13426.20270) 64-bit, the Display-method still works perfectly, but Send() returns "Sorry, something went wrong. You may want to try again".

    What I tried:

    • I removed PIA-references (Office 15) in order to use "Microsoft Office 16.0 Object Library" (COM) -> same behavior
    • tried Late binding using CreateObject("Outlook.Application") -> same behavior

    Any ideas?

    Regards,

    Patrick

    Tuesday, December 1, 2020 1:44 PM

All replies

  • Please post the relevant snippet of your code.

    Also, since you call Display, why do you also call Send? It is user's responsibility to click the Send button.


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

    Tuesday, December 1, 2020 3:26 PM
  • Hi Dimitry,

    While preparing and simplifying a sample for you, I found out that this problem is due to a call to "mail.GetInspector". I use this logic to keep outlooks default signature.

    ''' <summary>Tests for Outlook 365</summary>
        Public Shared Function SendTestEMailViaOutlook(ByVal sendDirectly As Boolean) As Boolean
            Dim returnValue As Boolean = True
            Dim outlook As New Microsoft.Office.Interop.Outlook.Application
            Dim mail As Microsoft.Office.Interop.Outlook.MailItem = Nothing
    
            ' simplified version
            Try
                mail = TryCast(outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem), Microsoft.Office.Interop.Outlook.MailItem)
                mail.To = "yourmail@domain.com"
                mail.Subject = "Patrick's mail test"
    
                Dim bodyText = "That's the body text..."
                'mail.Body = bodyText
    
                ' ----------------------------------------------------------------------------------
                ' Keep Outlooks signature to not overwrite it (this alternative uses HTML)
                Dim outlInsp As Microsoft.Office.Interop.Outlook.Inspector
                ' accessing the inspector loads the signature
                outlInsp = mail.GetInspector ' <--- only this line causes afterwards the send problem !!!
                outlInsp = Nothing
    
                ' convert new text to HTML 
                ' insert text with "class" to keep the same font
                Dim bodyHtml As String
                Dim htmlDoc As New mshtml.HTMLDocument ' Microsoft HTML Object Library
                Dim ihtmlDoc As mshtml.IHTMLDocument2 = DirectCast(htmlDoc, mshtml.IHTMLDocument2)
                With ihtmlDoc
                    .write("")
                    .close()
                    .body.innerText = bodyText
                    bodyHtml = .body.innerHTML
                End With
                mail.HTMLBody = Replace(mail.HTMLBody, "<div,
                                        "<div & bodyHtml & "</p>")
                ' ----------------------------------------------------------------------------------
    
                If sendDirectly Then
                    mail.Send()
                Else
                    mail.Display()
                    mail.Save()
                End If
            Catch ex As Exception
                returnValue = False
                MessageBox.Show("Problem " & vbCrLf & $"[{ex}]", PrintFunctions.MessageboxTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End Try
    
            Return returnValue
        End Function

    Is GetInspector no longer allowed with Outlook 365?

    Patrick

    Wednesday, December 2, 2020 8:36 AM
  • Calling GetInspector no longer adds signature to the email, only Display does.

    You can merge the HTML signature file with your own HTML body. but note that the two must be merged, not just concatenated and the styles and images must also be merged.

    If using Redemption is an option, its RDOSignature.Apply method allows to insert a signature without displaying the message:

     set Session = CreateObject("Redemption.RDOSession")
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
    set Drafts = Session.GetDefaultFolder(olFolderDrafts)
    set Msg = Drafts.Items.Add
    Msg.To = "dmitry@dimastr.com"
    Msg.Subject = "testing signatures"
    Msg.HTMLBody = "<html><body>some <b>bold</b> message text</body></html>"
    set Account = Session.Accounts.GetOrder(2).Item(1) 'first mail account
    if Not (Account Is Nothing) Then
      set Signature = Account.NewMessageSignature
      if Not (Signature Is Nothing) Then
        Signature.ApplyTo Msg, false 'apply at the bottom
      End If
    End If
    Msg.Display


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

    • Proposed as answer by KHURRAM RAHIM Wednesday, December 2, 2020 4:30 PM
    Wednesday, December 2, 2020 3:35 PM
  • Hi Dimitry,

    I already read your quote "as of July 2017, MailItem.GetInspector in Outlook 2016 no longer inserts the signature. Only MailItem.Display does" here:

    How to add default signature in Outlook

    I did some further tests and I think your statement is not correct. If I look "mail.HTMLBody" before and after "mail.GetInspector", GetInspector nevertheless loads the signature in the HTMLBody, this tested with Outlook 2016, 2019 and 365. Maybe Microsoft corrected the behavior in the meantime...

    So anyway GetInspector has a bug with Send on Outlook 365? Do you have a good connection to Microsofts Outlook team?

    Thanks,

    Patrick

    Thursday, December 3, 2020 9:03 AM