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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GW-Mail over VBA in Access, with more than two recipients!

Status
Not open for further replies.

Hasch2o

Programmer
Oct 1, 2001
12
CH
Hi everybody,

I've got following question:
I'm trying to send an E-Mail over VBA in Access with
this code:
Public Function Send_Mail(mysubject As String, textfeld As String, mailto As String)
Dim objGWApp As Application2
Dim objGWAccount As Account2
Dim objGWmsg As Message3
Set objGWApp = New Application2
Set objGWAccount = objGWApp.Login
Set objGWmsg = objGWAccount.MailBox.Messages.Add("GW.Message.Mail")
objGWmsg.BodyText = textfeld
objGWmsg.FromText = "ExVV-Datenbank"
objGWmsg.Subject = mysubject
objGWmsg.Recipients.Add (mailto)
objGWmsg.Send
Set objGWApp = Nothing
Set objGWAccount = Nothing
Set objGWmsg = Nothing
End Function

This is no problem, everything functions like i want,
but now, how can i add more then one recipient???
Do i have to add a second :
objGWmsg.Recipients.Add (xxxxxxx)
If yes, how can I resolve that this stays as
flexible as with one recipient??? This Function is
used by two or three other procedures, and i don't
know, how many recipients it will contain!!!

Can somebody help me with my problem

Greetins H-2-O

PS: Sorry, for the bad English :)
 
I just have this as a procedure & loop through it for each recipient but the GRoupwise API site has the following
"
Recipients
A collection of Recipient objects.


Properties
The following table lists properties along with their access and descriptions.

Property Access Description
Application
R/O
Application. The Application object.

Count
R/O
Long. The number of objects in this collection.

_NewEnum
R/O
Enumeration object. Implements IEnumVARIANT. For Windows only.

Parent
R/O
Message. The Message object that owns this collection.



Methods
Recipient Add(Address Address, [AddressTargetTypeConstants TargetType])
Creates an unresolved Recipient object from an Address object, then adds the Recipient object to the collection. The new Recipient's Address property is set to the Address object given, and its DisplayName, EmailAddress, and EmailType are copied from the Address object. If TargetType is omitted, egwTo is assumed. Returns the new Recipient. See Remarks below.

Recipient Add(Addresses Addresses, [AddressTargetTypeConstants TargetType])
Creates unresolved Recipients for each Address in the Addresses collection given, and adds each Recipient object to the collection. If TargetType is omitted, egwTo is assumed. Returns nothing. See Remarks below.

Recipient Add(String EmailAddress, [String EmailType], [AddressTargetTypeConstants TargetType])
Creates an unresolved Recipient from the EmailAddress, EmailType, and TargetType, then adds the Recipient object to the collection. If EmailType is omitted, an empty string ("") is assumed. If TargetType is omitted, egwTo is assumed. The new Recipient's Address property is set to Nothing and its DisplayName is set to EmailAddress. Returns the new Recipient. See Remarks below. See also AddressTargetTypeConstants.

Recipient AddByDisplayName(String DisplayName, [AddressTargetTypeConstants TargetType])
Creates an unresolved Recipient from DisplayName, then adds it to the collection. If DisplayName is an empty string (""), an exception is thrown. If TargetType is omitted, To is assumed. The new Recipient Address property is set to Nothing and its EmailAddress and EmailType are set to an empty string (""). Returns the new Recipient. See AddressTargetTypeConstants.

Recipient Item(Long Index)
DEFAULT. Returns the Recipient object located at the given Index in the collection. Valid indexes are 1 through Count inclusive. Throws an exception if the Index is outside of this range.

Resolve([AddressBook ResolveTo])
Performs a Resolve on each Recipient in the collection. If an error occurs, it leaves that recipient unresolved and proceeds to the next recipient. Throws an exception if any recipients failed to resolve. Check the Resolved property of each Recipient object to determine which ones failed.



Remarks
The Add method template is as follows:

Add(VARIANT P1, [VARIANT P2], [VARIANT P3])
The Add method checks the P1 type at runtime.
If P1 is an Address object, the first form of Add is assumed; P2, if present, must be a TargetType Enum of type AddressTargetTypeConstants, and P3 must not be present.

If P1 is an Addresses collection, the second form of Add is assumed; P2, if present, must be a TargetType Enum of type AddressTargetTypeConstants, and P3 must not be present.
If P1 is a String, the third form of Add is assumed; P2, if present, must be a string, and P3, if present, must be a Target Enum of type AddressTargetTypeConstants.


AddByDisplayName must be a separate method from Add, since EmailAddress and DisplayName are both Strings and cannot be distinguished by type.

A Recipients collection is refreshed when its parent object is refreshed. When a Recipients collection is refreshed, it recursively refreshes its contained Recipient objects.
"
The URL is
Hope this is of help.

Warwick
 
Did you end up finding a way to add more than one recipient without calling the send_email function each time or adding a new line to the function for each new recipient? I've tried doing the same thing, using info from the novell page, but I still haven't got anything to work.
 
I wasn't able to do exactly what you are looking for, but I did come close. What I did was enter the email addresses in a String, separating them by commas(you could use semicolons, or whatever you want). I then wrote a subroutine to split the string into an array of names that the email should be sent to. Finally, I used a for loop to pull each name out of the array and add it to the recipients.add function. If you would like more detail let me know.
 
Public Function Send_Mail(mysubject As String, textfeld As String, mailto As String)
Dim objGWApp As Application2
Dim objGWAccount As Account2
Dim objGWmsg As Message3
Set objGWApp = New Application2
Set objGWAccount = objGWApp.Login
Set objGWmsg = objGWAccount.MailBox.Messages.Add("GW.Message.Mail")
objGWmsg.BodyText = textfeld
objGWmsg.FromText = "ExVV-Datenbank"
objGWmsg.Subject = mysubject
objGWmsg.Recipients.Add (mailto)
objGWmsg.Send
Set objGWApp = Nothing
Set objGWAccount = Nothing
Set objGWmsg = Nothing
End Function

I tried running this code from Hasch2o and it bombs on
me. What am I missing?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top