OL2003 and Sending Mail via VBA

  • Thread starter Thread starter John Cranston
  • Start date Start date
J

John Cranston

I have an application that was written prior to OL2003. It uses VBA to send
mail to SMTP addresses from an SQL database. Outlook 2003 doesn't resolve
addresses/names correctly. The address is placed into the address, but the
display name is set to blank. When you look at the message in the OL Sent
Items, it looks like there is no recipient.

It is a custom program, so I have access to the code, but I can't find a way
to force it to make the display name and the address the same. Or even a
way to tell it a display name. CDO is not the preferred solution.
 
Perhaps posting the relevant code snippet that adds the addresses and
display names would shed some light.
 
New = CreateObject('Outlook.Application')
New.Subject = 'MessageSubject'
New.Body = 'Message Text'
Recip = New.Recipients.Add(SendToAddr)
Recip.Type = 1
New.Recipients.ResolveAll
New.Send


Pretty straight forward, but no display name.
 
Sorry... I mistyped the sample. I was try to condense it and when I read it
back, it didn't make sense

It should read:

App = CreateObject('Outlook.Application')
Session = App.GetNameSpace('MAPI')
Session.Logon(lcProfile)
Folder = Session.GetDefaultFolder(16)
New = Folder.Items.Add(0)

New.Subject = 'MessageSubject'
New.Body = 'Message Text'
Recip = New.Recipients.Add(SendToAddr)
Recip.Type = 1
New.Recipients.ResolveAll
New.Send
 
If this is VBA code then I'm not surprised that it's not working. You need
to use Set when you assign any object:
Set App = CreateObject('Outlook.Application')
Set Session = App.GetNameSpace('MAPI')
Set Folder = Session.GetDefaultFolder(16)
Set New = Folder.Items.Add(0)
Set Recip = New.Recipients.Add(SendToAddr)
 
Good point, but that is just my transcription. The e-mail works fine, it is
just the name doesn't show up when you look in the sent items.
 
Then you'll have to continue the thread with Dmitry and see if he comes up
with a solution. He would know more about the Redemption aspects.
 
I have tried it with an without Redemption. That is why I posted the
message 2 different ways.

It seems that when Outlook 2003 resolves the recipient names of a mail item
added through the Application Model (as opposed to the Outlook GUI), and the
address is not one of the contacts on file, the display name is set to Blank
or Null.

Mail added using Redemption has the same problem, but no security pop-ups.
 
If the display name is blank it should just show the SMTP address there. It
does here for me. Doesn't it do that for you?
 
No. I have traced the code. Right after the Resolve statement, I check the
Recipient Name and Address Properties and they are correct. Then look at
the e-mail in the sent items folder - Blank Name, no address shown. The
e-mail gets delivered. If I send an e-mail through the Outlook GUI to the
same address, name is displayed on the sent mail item.

I used Outlook Spy to look at both of these and the GUI mail has a display
name, the programmatically added mail does not.
 
I'll have to play with it more on both Outlook 2003 and earlier versions,
and file a bug with MS on this. Unless some fairly large customer complains
about it or there are many complaints however I wouldn't expect a hotfix for
it since the business case for that wouldn't be sufficient. It would
probably have to wait for Outlook 2003 SP2 to get fixed I'd imagine.
 
FWIW, I can't duplicate these symptoms in Outlook 2003. What type of mail
account(s) are involved?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top