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 olRecipientsIf 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
End If
Next
MessageBox.Show(“To: ” & strToEmails & “Cc: ” & strCcEmails & “BCc: ” & strBCcEmails)
Hope this helps!
Hello,
Could you please help me.
I am trying to use vb script to edit outlook in order to meet my requirement.
my requirement:
1. before sending an email, user must get a prompt if they want to send this email or not.
2. in the prompt or message box above, i must also display the recipients email address.
the first part is working fine, but i am really stuck with the second part i.e. in the message box I must include the email addresses in the CC and BCc field.
your help will be much appreciated.
thank you.
Hi Roy,
VB Script?
Assuming you are using VB.NET. Is the above code not working for you?
What is the account type of the email that is configured in Outlook? Is that POP3 or Exchange?
If it is exchange, you need to use another method to extract the recipients from email.
I wrote a blog post on how to get recipients from exchange account also. You can find it in this blog.
Hope this helps! Let me know, if you have any queries.
Hi Pranav,
Thanks a lot for getting back to me.
Well I am using imap in Outlook 2007.
Actually, I have already added the lines below which prompts the user whether to send the email or not.
the lines are:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim intRes As Integer
Dim strMsg As String
strMsg = “Do you really wantt o send this message now?”
intRes = MsgBox(strMsg, vbYesNo + vbDefaultButton1, “Confirm Send “)
If intRes = vbNo Then
Cancel = True
End If
End Sub
As i mentioned this part is working.
The last final bit is to add the recipient email address in the message box so that the user can easily see their addressed recipients i.e the email addresses in the cc and bcc fields.
please friend, your help will be much appreciated.
thank you.