Seems to be a simple task. Right? But, not exactly.
Say olMailItem is the object of Outlook.MailItem. From olMailItem.TO, olMailItem.CC and olMailItem.BCC, we get the names of the recipients from the Outlook contacts. But not their email addresses.
To get email addresses, we can use the following code.
Dim olRecipients As Outlook.Recipients
olRecipients = olMailItem.Recipients
Dim strToEmails, strCcEmails, strBCcEmails As String
For Each olRecipient As Outlook.Recipient In olRecipients
If olRecipient.Type = Outlook.OlMailRecipientType.olTo Then
strToEmails += olRecipient.Address & vbCrLf
ElseIf olRecipient.Type = Outlook.OlMailRecipientType.olCC Then
strCcEmails += olRecipient.Address & vbCrLf
ElseIf olRecipient.Type = Outlook.OlMailRecipientType.olBCC Then
strBCcEmails += olRecipient.Address & vbCrLf
MessageBox.Show(“To: ” & strToEmails & “Cc: ” & strCcEmails & “BCc: ” & strBCcEmails)
Hope this helps!