Link to home
Start Free TrialLog in
Avatar of Sammi110599
Sammi110599

asked on

Problems sending a multiple recipient outlook mail from Notes.

I have an action button on a form in Lotus Notes that creates an outlook mail message, assigns values from the document to the To, Subject, and Body fields and sends it.  It works fine if I give it one name to send to.  If I try to give it multiple recipients it gives the following error:

OutILib.dll: Outlook does not recognize one or more names.

The names are spelled correctly and they are valid in Outlook.  How do I tell Outlook that I want the message to go to multiple people?  I am pulling the names from a SendTo field on the current document.  Here is the code:

Sub CreateOutlookMsg (doc As NotesDocument)
     Dim Sendnames As Notesitem
     Set Sendnames = doc.GetFirstItem("SendTo")
     
 'Get an outlook application object
     Set objSession = CreateObject("Outlook.Application")
     
'Create a new message
     Set objMessage= objSession.CreateItem(olMailItem)
         
'Set the subject and message fields
     cnumber = doc.ComplaintNumber(0)
     createdby = doc.Author(0)
     
'Set the SendTo Fields on the
     recips = Sendnames.Text
     Subject$ = "New Suspected Adverse Drug Reaction report  (THIS IS A TEST)"
     Message$ = "A new report has been submitted by " & createdby & _
     " for record " & cnumber & "."
     
     Set objRecipient = objMessage.Recipients.Add (recips)
     objMessage.subject = Subject$
     objMessage.Body = Message$
     Call objMessage.Send()
End Sub


Thanks for any help you can provide!
Avatar of Sammi110599
Sammi110599

ASKER

Edited text of question.
Hi sammy !

Try the same thing manually by adding multiple recipients.  If you succeed then look into your code.

I guess item.text gives the list values separated by semicolons.  This may be a problem with Outlook.  Try replacing these semicolons with commas and send the memo.

All the best.

:)
Arun
Arun,

Per your suggestion, I manually added the names to an Outlook message in the same format they are being passed in the script.  That worked but Outlook checks the names and re-formats them based on what is in the Outlook address book anyway.  I then hard-coded the 'recips' variable as a literal string with the names separated by commas. e.g. "Joe Blow, Bob Jones, Jane Doe"  This gave me the same error.  Finally I tried giving the 'recips' variable another literal string with the names formatted the way Outlook formats them.  i.e.  "Jones Bob CV USAT EXC" (our organizational stuff).  That gave me the same error.

Any other ideas?

FYI:  I did try passing item.Values to the recipients field like this:

Set Sendnames = doc.GetFirstItem("SendTo")
..
..
..
recips = Sendnames.Values
..
..
..
Set objRecipient = objMessage.Recipients.Add (recips)

This results in an error on the "Set objRecipient..." line that says "Automation object argument type mismatch".  I assume its looking for text?

Again, thanks for your help.
I solved it!!

First, I changed the 'Sendnames' object reference variable to 'Item'(don't know why this helped but it seemed to).  I then put the "Set objRecipient = ..." line in a ForAll loop.  This goes through each value in the 'SendTo' field and adds it as a recipient to the Outlook message.  Here is the code:

Forall n In Item.Values
          Set objRecipient = objMessage.Recipients.Add (n)
     End Forall

Thanks for your help earlier!
ASKER CERTIFIED SOLUTION
Avatar of Arunkumar
Arunkumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial