System administrator unable to send olBCC mail

0

I have a custom outlook appointment, from which I want to automatically BCC a mail upon sending my a appointment invitation.

Function Item_Send()
    Set oMsg = Application.ActiveInspector.CurrentItem 
    With oMsg 
        Set objRecip = Item.Recipients.Add("MyEmail@mail.com")
        objRecip.Type = olBCC
        objRecip.Resolve 
    End With
    Set oMsg = Nothing 
End Function

Everything seems to work fine - My email is attached as BCC, and the appointment is successfully being send.

However, in my inbox I'm getting a mail, that the BCC mail could not be reached.

Your message did not reach some or all of the intended recipients.

Subject:
Sent: 18/06/2020 14:49

The following recipient(s) cannot be reached:

MyEmail on 18/06/2020 14:49 'MyEmail@mail.com' on 18/06/2020 14:49 This message could not be sent. Try sending the message again later, or contact your network administrator.


Diagnostic information for administrators:


Error is [0x80070057-0x00000000-0x00000000]. Submit-Message failed: message id(23), failure enum(7), HResult(0x80070057), EC(-2147024809).

Why is this error occuring? My mail is not incorrect.

vba
outlook
asked on Stack Overflow Jun 18, 2020 by Jeppe Christensen • edited Jun 22, 2020 by Martijn Pieters

1 Answer

0

It is not clear where the Item object comes from.

First of all, the Type property for MeetingItem recipients can be one of the following OlMeetingRecipientType constants: olOptional, olOrganizer, olRequired, or olResource. If you want to send a BCC I'd recommend creating a new mail item and copy properties to the new item.


Anyway, the Resolve method returns a boolean value which is true if the object was resolved; otherwise, false. For example, that is how you need to check this out:

Sub AssignTask() 
 Dim myItem As Outlook.TaskItem
 Dim myDelegate As Outlook.Recipient

 Set MyItem = Application.CreateItem(olTaskItem) 

 MyItem.Assign 

 Set myDelegate = MyItem.Recipients.Add("Eugene Astafiev") 

 myDelegate.Resolve 

 If myDelegate.Resolved Then 

   myItem.Subject = "Prepare Agenda For Meeting" 

   myItem.DueDate = Now + 30 

   myItem.Display 

   myItem.Send 

 End If 

End Sub

Be aware, the ItemSend event handler accepts two parameters. For example, the following code in VB.NET works like a charm on my machine:

Imports System.Runtime.InteropServices
' ...
Private Sub OnItemSend(Item As System.Object, ByRef Cancel As Boolean) _
                       Handles Application.ItemSend
    Dim recipient As Outlook.Recipient = Nothing
    Dim recipients As Outlook.Recipients = Nothing    
    Dim mail As Outlook.MailItem = TryCast(Item, Outlook.MailItem)
    If Not IsNothing(mail) Then
        Dim addToSubject As String = " !IMPORTANT"
        Dim addToBody As String = "Sent from my Outlook 2010"
        If Not mail.Subject.Contains(addToSubject) Then
            mail.Subject += addToSubject
        End If
        If Not mail.Body.EndsWith(addToBody) Then
            mail.Body += addToBody
        End If
        recipients = mail.Recipients
        recipient = recipients.Add("Eugene Astafiev")
        recipient.Type = Outlook.OlMailRecipientType.olBCC
        recipient.Resolve()
        If Not IsNothing(recipient) Then Marshal.ReleaseComObject(recipient)
        If Not IsNothing(recipients) Then Marshal.ReleaseComObject(recipients)
    End If
End Sub

This event triggers right after the user clicks the Send button in Outlook (before the inspector window is closed) or when the Send method of Outlook items is called. The ItemSend event provides two parameters to the programmer:

  • The Item object – an Outlook item that is going to be sent. It can be represented by the AppointmentItem, MailItem, MeetingItem, MobileItem, SharingItem, TaskItem classes.
  • The Cancel parameter – allows you to cancel sending in Outlook. The default value is false. If you set the Cancel parameter to true in the event handler, the sending process is canceled and the inspector window is shown to the user.

Read more about that in the How To: Change an Outlook e-mail message before sending using C# or VB.NET article.

answered on Stack Overflow Jun 18, 2020 by Eugene Astafiev • edited Jun 18, 2020 by Eugene Astafiev

User contributions licensed under CC BY-SA 3.0