Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple attachments and Multiple recipients 1

Status
Not open for further replies.

Stuartp

Technical User
Feb 22, 2001
178
0
0
GB
I am using MAPI controls in my VB6 program to send emails to people and attach files. The code I have used so far is:

Code:
MAPISession1.SignOn

MAPIMessages1.SessionID = MAPISession1.SessionID

MAPIMessages1.Compose

MAPIMessages1.RecipAddress = "stuartcomm@yahoo.com"

MAPIMessages1.AddressResolveUI = True

MAPIMessages1.ResolveName

MAPIMessages1.MsgSubject = "Sales Report"

MAPIMessages1.MsgNoteText = "Reports"

MAPIMessages1.AttachmentPathName = "C:\Program Files\Ordertracker\yorksales.pdf"

MAPIMessages1.Send

MAPISession1.SignOff


This works fine for sending one attachment to one recipient. But how do I add multiple attachments or recipients? I have read about the attachmentIndex property and so on but have no idea how to use it.

Thanks for your help.

Stuart
 
For mutiple recipients you just change the RecipIndex property. Each address will be having unique recipindex property, which will start from 0.

Same as for Mutiple attachment you change AttachmentIndex

From
Pandi
 
From what I remember, you just set AttachmentIndex before adding an attachment. e.g.
Code:
With MAPIMessages1
  .AttachmentIndex=0
  .AttachmentName="Filename1.ext"
  .AttachmentIndex=1
  .AttachmentName="Filename2.ext"
  .AttachmentIndex=2
  .AttachmentName="Filename3.ext"
End With 'MAPIMessages1
The AttachmentCount property is updated automatically, I think.

To use multiple addresses I think you can just separate them with semi-colons:
Code:
MAPIMessages1.RecipAddress = "stuartcomm@yahoo.com;me:here.com"

It's been a while since I used MAPI - let me know if it works out.

Daren

Must think of a witty signature
 
Pandi is right - I should have read the help:
Code:
With MAPIMessages1
  .RecipIndex=0
  .RecipAddress="stuartcomm@yahoo.com"
  .RecipIndex=1
  .RecipAddress="me@here.com"
End With 'MAPIMessages1

If you have a lot then it is obviously easier to add them in a loop.

Hope this helps

Daren
Must think of a witty signature
 
Thanks for your help so far. Running it now I receive:

Run time error 32002 - Unspecified Error has occured

This is on the bit of code Mapimessages1.send

Any ideas?

Thanks, STuart
 
Could be having problems with resolving address names? Not sure. Posting the code as you have it now might give us a clue.
Must think of a witty signature
 
Code:
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
With MAPIMessages1
.RecipIndex = 0
.RecipAddress = "stuartcomm@yahoo.com"
.RecipIndex = 1
.RecipAddress = "stuartpyefinch@hotmail.com"
.AttachmentIndex = 0
.AttachmentPathName = "C:\Program Files\Ordertracker\yorksales.pdf"
.AttachmentIndex = 1
.AttachmentPathName = "C:\Program Files\Ordertracker\groupsales.pdf"
End With

MAPIMessages1.AddressResolveUI = True
MAPIMessages1.ResolveName
MAPIMessages1.MsgSubject = "Sales Report"
MAPIMessages1.MsgNoteText = "Please find attached sales figures for yesterday." & Chr(13) & Chr(13) & "Regards" & Chr(13) & Chr(13) & "Stuart Padmore"

MAPIMessages1.Send
MAPISession1.SignOff

Here it is!!

Stuart
 
I think you need to use .ResolveName after each address is added:
Code:
With MAPIMessages1

  '* * Addresses * *
  .AddressResolveUI = True 'Put this before trying to resolve

  .RecipIndex = 0  
  .RecipAddress = "stuartcomm@yahoo.com"  
  .ResolveName

  .RecipIndex = 1  
  .RecipAddress = "stuartpyefinch@hotmail.com"
  .ResolveName
  
  '* * Add attachments * *
  .AttachmentIndex = 0 
  .AttachmentPathName = "C:\Program Files\Ordertracker\yorksales.pdf"  

  .AttachmentIndex = 1
  .AttachmentPathName = "C:\Program Files\Ordertracker\groupsales.pdf"
    
  '* * Subject and body * *
  .MsgSubject = "Sales Report"
  .MsgNoteText = "Please find attached sales figures for yesterday." & Chr(13) & Chr(13) & "Regards" & Chr(13) & Chr(13) & "Stuart Padmore"

  .Send

End With 'MAPIMessages1

When I try it I'm getting an error on the "ResolveName". I think this is either because the addresses that I am testing with aren't in my address book or because the Outlook security update is interfering with the MAPI control. You shouldn't need to resolve the addresses - try commenting those lines out.

Unfortunately I am also getting a "not supported" error on the .Send, so it may be that the security patch is interfering. Are you using MS Exchange and Outlook?

Must think of a witty signature
 
Yes this has done the trick! However I have discovered that when adding multiple attachments you also need to set the position of it, else an Unspecified Error will occur. so you end up with:

Code:
With MAPIMessages1
.AttachmentIndex = 0
.AttachmentPosition = 0
.AttachmentPathName = "C:\Program Files\Ordertracker\yorksales.pdf"
.AttachmentIndex = 1
.AttachmentPosition = 1
.AttachmentPathName = "C:\Program Files\Ordertracker\groupsales.pdf"
End With

We are using Outlook 2001 with I think SP1 installed, but it connects to an MS Exchange 2000 server.

Thanks for your help!

Stuart
 
Well spotted! I forgot about AttachmentPosition.

Glad it worked.

Daren
Must think of a witty signature
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top