[Resolved] Email address chokes Outlook.
OK, I have a macro that generates worksheets to send to another department. That department added a new member who's email address managed to break my mail routine, and I can't figure out why. I use the internal network email addressing ("Lastname, Firstname") because it's a lot easier than remembering who all the addresses belong to (our address system is kind of cryptic). Here's the code I use:
VB Code:
If Len(frmOutputOpts.cmbEmailTo.Text) > 0 Then 'ComboBox with email addresses.
Set oOutlook = New Outlook.Application
Set oEmail = oOutlook.CreateItem(olMailItem)
With oEmail
If frmOutputOpts.cbxCC.Value = True Then
Set oRecip = .Recipients.Add("Xxxxxxxxx, Xxxxx") 'Real name removed.
oRecip.Type = olCC
End If
.Recipients.Add (frmOutputOpts.cmbEmailTo.Text)
.Subject = frmDeathClaim.txtLastName.Text + ", " + frmDeathClaim.txtPolicyNum.Text
Call .Attachments.Add(sSaveAs, olByValue, 1, oEmail.Subject + ".doc")
.Send
End With
Set oRecip = Nothing
Set oEmail = Nothing
Set oOutlook = Nothing
End If
It gives Error number -1179631611, Outlook does not recognize one or more names, on the .Send line. Strange thing is, I can copy and paste the email address from my ComboBox into Outlook manually, and it works fine from there. Just not through code. The new email address is:
Xxxxxxx, Xxxxx (Life Annuity Claims)
I'm guessing it has something to do with the ()'s. I can do a workaround and use the [email protected] format, but I don't want to hard-code addresses into the macro.
Any ideas?
Re: Email address chokes Outlook.
Looks like an old compuserve address. I think they've converted all of them to a more conventional naming expression.
Re: Email address chokes Outlook.
Actually, it's our internal intranet mail system. Problem is, when more than one person in the company has the same name, they stick the department name in parentheses after the "Last, First". The normal ([email protected]) email addresses are 5 character alfa-numerics that follow one of about 6 different conventions depending on when the individual joined the company. :rolleyes:
Re: Email address chokes Outlook.
The parenthesis is used as a delimiter for things like the "Display As" and the "File As".
I feel you pain on this one. :( How about trying to resolve the address and catch the errors?
VB Code:
If Len(frmOutputOpts.cmbEmailTo.Text) > 0 Then 'ComboBox with email addresses.
Set oOutlook = New Outlook.Application
Set oEmail = oOutlook.CreateItem(olMailItem)
With oEmail
If frmOutputOpts.cbxCC.Value = True Then
Set oRecip = .Recipients.Add("Xxxxxxxxx, Xxxxx") 'Real name removed.
oRecip.Type = olCC
If Not .Recipients.ResolveAll Then 'Or however else you want to handle the error
MsgBox "Email address error!"
End If
End If
.Recipients.Add (frmOutputOpts.cmbEmailTo.Text) 'Will the To also have the "(" chars?
.Subject = frmDeathClaim.txtLastName.Text + ", " + frmDeathClaim.txtPolicyNum.Text
Call .Attachments.Add(sSaveAs, olByValue, 1, oEmail.Subject + ".doc")
.Send
End With
Set oRecip = Nothing
Set oEmail = Nothing
Set oOutlook = Nothing
End If
Re: Email address chokes Outlook.
OK, don't ask me why, but this fixed it:
VB Code:
Set oRecip = .Recipients.Add(frmOutputOpts.cmbEmailTo.Text)
oRecip.Resolve
For some reason it likes it when I resolve it explicitly, but not when I let .Send do it. Thanks RobDog888.
Re: [Resolved] Email address chokes Outlook.
Thanks :thumb:
Resolve verifies against the Address book or Contacts that the Addresses added to the
mailitem that they are valid
Re: [Resolved] Email address chokes Outlook.
Never had that problem, but it's a handy thing to know.