Reputation: 393
My code will take the email address from the .To
property, and send another email.
When the address is autocompleted, it has John Smith instead of [email protected]. The .To
is empty for VBA code.
Is it possible to bypass it?
Dim objMail As Outlook.MailItem
Dim objNewMail1 As Outlook.MailItem
Dim strTo As String
strTo = objMail.To
Set objNewMail1 = Application.CreateItem(olMailItem)
With objNewMail1
.To = strTo
.Send
End With
Upvotes: 1
Views: 214
Reputation: 66286
Do not use the To
/ CC
/ BCC
properties - they, generally, include only the display names, not email addresses.
Loop through all recipients in the MailItem.Recipients
collection and use the Recipient.Address
property - keep in mind you might have an EX type address, nit SMTP in case of Exchange, you might have to use Recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress
(GetExchangeUser
will return null for the non-Exchange address entries).
The recipient kind (olTo
/ olCC
/ olBCC
) is stored in the Recipient.Type
property.
dim recip, newRecip
...
With objNewMail1
for each recip in objMail.Recipients
set newRecip = .Recipients.Add(recip.Address)
newRecip.Type = recip.Type
next
.Send
End With
Upvotes: 2