473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Outlook : Select Address of a Contact

NeoPa
32,556 Expert Mod 16PB
I am using Outlook Automation (from within Access) to create a MailItem object (an email to you and me). The {MailItem}.recipients.Add() method is often fine for adding an addressee (from the Contacts folder), but I find that I am unable to select the individual SMTP address where the contact has more than one.

If anyone knows how this can be done then I'd be interested to hear.
Jul 7 '08 #1

✓ answered by nico5038

Guess you need to process the items of the Recipients Collection Object, see: http://msdn.microsoft.com/en-us/libr...CHG.10%29.aspx

Nic;o)

17 4449
nico5038
3,080 Expert 2GB
Guess you need to process the items of the Recipients Collection Object, see: http://msdn.microsoft.com/en-us/libr...CHG.10%29.aspx

Nic;o)
Jul 7 '08 #2
NeoPa
32,556 Expert Mod 16PB
Thanks Nico.

I was already looking at the Recipient object of course, but your link pointed me at a resource that explained it better than what I'd found in the Help system. Obviously I'd Googled, but hadn't found what I needed.

When I have finalised my code (after finalising my understanding of course) I'll post some more info for anyone else to find with similar problems.

Cheers :)

PS. The bit I found that I think most likely to give me what I need is http://msdn.microsoft.com/en-us/libr...EXCHG.10).aspx.
Jul 8 '08 #3
mshmyob
904 Expert 512MB
Hey Neo. I am working on a new project and will need to implement an email portion. When you are done can you send me some stuff you did maybe I can use some of it. It will save me a lot of time. I'm not quite ready for that aspect but should be in a couple weeks.


cheers,
Jul 8 '08 #4
NeoPa
32,556 Expert Mod 16PB
Just let me know nearer the time. I will have made more progress then.
You can also let me know (then) exactly what you're looking for.

PS. I should warn you that this code does fall foul of fairly annoying Outlook warnings that non-Outlook software is trying to (1) access addresses and (2) send email on your behalf.

This is something I intend to progress with, but to date I've hit problems.
Jul 8 '08 #5
nico5038
3,080 Expert 2GB
Instead of Outlook you might try the CDO object for emailing.
Check: http://www.paulsadowski.com/WSH/cdo.htm

Nic;o)
Jul 8 '08 #6
NeoPa
32,556 Expert Mod 16PB
That looks very interesting Nico - Thanks.

I am most of the way there using the standard Outlook object model, but this one may prove a better solution for me. I will certainly look into it and post back my comments. That may be a bit delayed though, as I am now working on another aspect of this particular project where I have to dig up the correct data that later will be e-mailed or FTPed across to the customer.

I know nothing about CDO at this time, so I will need to read up some. I do know that the firewalls we have here will disallow any SMTP traffic from anywhere but a few well restricted servers (and all the Exchange servers are set not to allow SMTP relaying). Had it not been for that I think I would have been happiest simply knocking an SMTP solution together.

All this because a bunch of personality-less morons decided to use the internet to spread their detritus. Anyway, all good fun.
Jul 9 '08 #7
NeoPa
32,556 Expert Mod 16PB
PS. From my initial research it seems that CDO does use the SMTP protocol exclusively, which puts it out of scope for me I'm afraid.

I will update the thread with any progress I make using Outlook automation.

I will include here a link that was passed to me that may prove promising (Avoiding Excessive Security Warnings when Sending Automated E-mail Messages). This deals with problems I have already encountered using this method. Hopefully this link will enable me to get around them.
Jul 11 '08 #8
nico5038
3,080 Expert 2GB
Good link NeoPa, shows that when SMTP is allowed the CDO is the easy way to "bypass" the Outlook Object model build-in warnings. Guess the "morons" found that too <LOL>

Nic;o)
Jul 11 '08 #9
NeoPa
32,556 Expert Mod 16PB
I'm afraid so Nico. There was a flood of virus payloads which included a basic SMTP engine that ran on the PC itself :(

I first found that out when an Exchange server I was responsible for was flagged as an open relay (it would allow SMTP messages to be sent on when it determined the address was not local). I had to fix it and then apply to be rechecked before I could get it removed from the blacklist (Various servers were refusing to accept any mail from us).

It seems there were two methods used by the virus software :
  1. SMTP via the local mail server. This gives the e-mails the impression of being more kosher.
  2. SMTP straight out to the web.
To block the first I needed to tighten up the security on my Exchange server. To block the second I needed to block SMTP traffic on the firewall from all internal addresses except my Exchange server.

As you will see, this doesn't leave much scope for a general purpose SMTP based routine in my code :(
Jul 14 '08 #10
mshmyob
904 Expert 512MB
Hello Neo,

I am now ready to look at the e-mail part of my app. Would you mind sending me anything you have got working (in particular how you got around the security messages). I will even trade if need be. I just created a very nice Calendar that allows you to add events such as meetings, to-do, etc., multiple participants, and such. I could trade you that if a calendar/scheduler is of any use to you.

You can PM me for email address.

cheers,
Rob
Jul 30 '08 #11
NeoPa
32,556 Expert Mod 16PB
Rob,

My e-mail project has been delayed further.

I am now using FTP to transfer this current set of files to the customer, although I would like to include e-mailing in my repertoire once this is finished. I hope to reduce the manual workload considerably by enabling this.

I haven't made much further progress than my last post on this though I'm afraid. I have the ability to code the sending of the mail, but the security is something I've only found links for.

I suggest, unless you have similar restrictions yourself with respect to SMTP, that you check out what CDO can do for you (Re Nico's post). If not, check out my earlier link and see if you can make some progress with that.

PS. Thanks for the offer of your code. I'll bear it in mind if ever I need something along those lines. I'm also more than happy to share anything I manage to come up with if it can be of any use to you. Unfortunately, that's not likely to start for some weeks now, and even that's assuming other priority work is not inserted ahead of it (I hope not though as this is something I really want to get cracked).
Jul 31 '08 #12
NeoPa
32,556 Expert Mod 16PB
This module (only half-finished I'm afraid) is as far as I've got so far. Nothing's finished yet (specifically some comments not implemented yet) but SendEM can send an email - albeit with all the security popups getting in the way :(
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private appOutlook As Outlook.Application
  5.  
  6. 'SendEM Sends an email
  7. 'For each address, any text found in <> will be treated as an SMTP address.
  8. 'An attempt is first made to refer to an object with a matching name.
  9. 'If this succeeds, but the address is ambiguous, the SMTP address will be used
  10. ' to resolve it.
  11. 'If no matching item is found then it will create a simple SMTP: entry
  12. ' of the following format : "Display Name<SMTP Address>".
  13. Public Function SendEM(Optional ByVal strTo As String, _
  14.                        Optional ByVal strCC As String, _
  15.                        Optional ByVal strBCC As String, _
  16.                        Optional ByVal strSubject As String, _
  17.                        Optional ByVal strBody As String, _
  18.                        Optional ByVal strAttachments As String) As Boolean
  19.     Dim blnOpen As Boolean
  20.     Dim strItem As String
  21.     Dim miMail As MailItem
  22.  
  23.     SendEM = False
  24.     blnOpen = Not (appOutlook Is Nothing)
  25.     If Not blnOpen Then
  26.         On Error Resume Next
  27.         Set appOutlook = GetObject(Class:="Outlook.Application")
  28.         On Error GoTo 0
  29.         blnOpen = Not (appOutlook Is Nothing)
  30.         If Not blnOpen Then _
  31.             Set appOutlook = CreateObject(Class:="Outlook.Application")
  32.     End If
  33.     With appOutlook
  34.         Set miMail = .CreateItem(ItemType:=olMailItem)
  35.         With miMail
  36.             Call .Display
  37.             Call AddRecipient(miMail, strTo, olTo)
  38.             Call AddRecipient(miMail, strCC, olCC)
  39.             Call AddRecipient(miMail, strBCC, olBCC)
  40.             .Subject = strSubject
  41.             .Body = strBody & .Body
  42.             Call .Send
  43.         End With
  44.         If Not blnOpen Then Set appOutlook = Nothing
  45.     End With
  46. End Function
  47.  
  48. Private Function AddRecipient(ByRef miMail As MailItem, _
  49.                               strList As String, _
  50.                               lngType As Long) As Boolean
  51.     Dim varItem As Variant
  52.  
  53.     With miMail.Recipients
  54.         For Each varItem In Split(strList, ";")
  55.             With .Add(varItem)
  56.                 .Type = lngType
  57.                 AddRecipient = Not .Resolve
  58.                 If AddRecipient Then Exit Function
  59.             End With
  60.         Next varItem
  61.     End With
  62. End Function
  63.  
  64. 'Some sample code from Microsoft
  65. ' function to attempt ambiguous name resolution (ANR)
  66. Private Function TryANR(objRecip As Recipient) As Boolean
  67.     Dim objAmbigEntries As AddressEntries ' possible resolutions
  68.     Dim strChosenID As String ' ID of address entry chosen by user
  69.  
  70.     ' ... set up error handling ...
  71.     Set objAmbigEntries = objRecip.AmbiguousNames
  72.     If objAmbigEntries Is Nothing Then
  73.         MsgBox "No eligible names for resolution"
  74.         objRecip.Delete ' nothing else can be done at this point
  75.         TryANR = False
  76.     Else
  77.         ' show address entries to user so one can be chosen, and save its
  78.         ' entry identifier: strChosenID = objAddrEntry.ID
  79.         objRecip.ID = strChosenID
  80.         TryANR = True
  81.     End If
  82. End Function
  83.  
  84. Public Function SendItem(Optional ByVal strTo As String, _
  85.                          Optional ByVal strCC As String, _
  86.                          Optional ByVal strBCC As String, _
  87.                          Optional ByVal strSubject As String, _
  88.                          Optional ByVal strBody As String, _
  89.                          Optional ByVal strAttachments As String) As Boolean
  90.  
  91. End Function
Jul 31 '08 #13
mshmyob
904 Expert 512MB
Thanks. I just started to look into the email problems and it looks like Extended MAPI might be the way to go instead of standard MAPI. Extended MAPI eliminates the problems of popups. If I get the Extended MAPI to work I will let you know.

cheers,
Jul 31 '08 #14
NeoPa
32,556 Expert Mod 16PB
Cheers Rob.

If that proves true (& I may get to start looking again in mid August sometime if things go according to plan) then I too will be very interested.

If I get anywhere I'll keep you posted :)
Jul 31 '08 #15
NeoPa
32,556 Expert Mod 16PB
Did you ever get anywhere with this Rob?

I'm not working on it again, but I'm still interested to see code reflecting a technique that can both be safe, and bypass the security warnings.
Oct 17 '09 #16
mshmyob
904 Expert 512MB
@NeoPa
Sorry for the delay Neo. I haven't checked for a few days. I am intending to try to get this working http://www.codeproject.com/KB/IP/CMapiEx.aspx. I have talked to the developer and he thinks it should work but has not tried it in VBA. It does work in VB.

I did not have time for my project to check in detail so I had to go with a commercial version so I went with MAILBEE.

But I would like to try and get the above free version working. When I get time I will look into it some more.

cheers,
Oct 20 '09 #17
NeoPa
32,556 Expert Mod 16PB
Sounds interesting. Likewise I don't have the scope to devote time to this at work atm. I'll catch any future posts on here though. Also, I'll post if I manage to get any progress myself.
Oct 20 '09 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Kurt | last post by:
Hi We are developing an off-the-shelf software suite for a certain business sector. Most of the program is simply a GUI on top of some .mdb files. Its a .net application written in c# One...
3
by: scott | last post by:
Anyone have a link to syntax that could create an outlook vcard file format? all examples i find are for doing it inside outlook with .net. i'm just looking for an ASP solution.
4
by: lauren quantrell | last post by:
Is there a way to open the MS Outlook address book using VBA and then be able to do something with the return value? I want users to click an icon to open the Outlook address book then when an...
0
by: Bob Avallone | last post by:
MetaPro Systems Inc. Visual Studio Dot Net Tips & Tricks #3 – Direct Access to Your Outlook Address Book. Project Type: VS.NET Windows Application Code Behind: Visual Basic I have a project...
5
by: TM | last post by:
I would like to write a little app in Visual Basic .net as an add-in to Outlook 2003 so that I can quickly get a list of contact names and email addresses, then when I click on a name or email...
1
by: charliej2001 | last post by:
Hi all My access database has import/export capabiltiy of contact details between outlook. The database is getting big now (1000+ contacts) and so are the outlook address books that have the...
4
by: kannan | last post by:
Hi, I am new to C# and It may be a simple question. I am trying to loop through MS-Outlook object Contact address list. I can able to find the count using following line. int iAddresscount =...
1
by: kannan | last post by:
Hi, I am trying to loop through outlook contact address and display in messagebox. I have used following code: Outlook._Application olApp = new Outlook.ApplicationClass(); Outlook._NameSpace...
1
by: Phil Stanton | last post by:
I have a Yacht Club Db with names addresse phone nos, emails etc. I want to export them to Outlook. No problem in getting them into the contact folder. My problem is I have a folder within the...
0
by: mkhan | last post by:
Hi, i have been having trouble how to open the To Contacts list (address book) of a mail message in outlook using vb.net from where the user would be able to select a email address and would be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.