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

Emails From VB 1

Status
Not open for further replies.

mans

Programmer
Joined
Mar 18, 2000
Messages
136
Location
AU
Hello,

I have been attempting to use the code below to send multiple emails and it does not work. I have searched this site and there is alot of info about emails from VB but I am not clear on sending multiple emails at one time. I have no problem hardcoding multiple email addresses and sending them. I am using VB6 (and Access2000) and have a table and a field within it called email, I wish the code to view all of the email names (RecipDisplayName) within the email field and place them in the "To:" box (separated by a colon). As you can see below, I have tried the Do-Loop method. I would greatley appreciate any help.

sPath = App.Path & "\db1.mdb"
Set daoDB36 = DBEngine(0).OpenDatabase(sPath)

Set rs = daoDB36.OpenRecordset("Select email from email")
Set Data1.Recordset = rs
Dim h As Integer

'MAPI constants from CONSTANT.TXT file:
Const SESSION_SIGNON = 1
Const MESSAGE_COMPOSE = 6
Const ATTACHTYPE_DATA = 0
Const RECIPTYPE_TO = 1
Const RECIPTYPE_CC = 2
Const MESSAGE_RESOLVENAME = 13
Const MESSAGE_SEND = 3
Const SESSION_SIGNOFF = 2


MAPISession1.Action = SESSION_SIGNON
MAPIMessages1.SessionID = Form1.MAPISession1.SessionID
MAPIMessages1.Action = MESSAGE_COMPOSE


MAPIMessages1.MsgSubject = Text2
MAPIMessages1.MsgNoteText = Text1
MAPIMessages1.AttachmentPosition = 0
MAPIMessages1.AttachmentType = ATTACHTYPE_DATA
h = 0

Do While Not rs.EOF
h = h + 1

MAPIMessages1.RecipIndex = h
MAPIMessages1.RecipType = RECIPTYPE_TO
MAPIMessages1.RecipDisplayName = rs!email
rs.MoveNext

Loop

MAPIMessages1.Action = MESSAGE_RESOLVENAME
MAPIMessages1.Action = MESSAGE_SEND

MAPISession1.Action = SESSION_SIGNOFF

Thanks
 
I would say you either need to add each recipiant to the list using a different method or you my try a "; " after each recipiants name. Typically a multi user email looks like this:

user1@isp1.com; user2@isp2.com; user3@isp3.net; user4@isp4.org;

You might try building a string like that and then submitting the names all at once, or you'll have to find another property like .Add where you can keep adding names to the recipiant list. If you build the string, use the loop to build it and pull the recipiant code out after the loop.

It looks like in the code you have, you keep overwriting one user with the next user. If I had to guess, only the last user gets the email.

Good Luck, Snaggs
tribesaddict@swbell.net
 
Going on the code above, I would think that it is easier to use the Outlook object model to send e mails.
This method only takes a few lines. If you want I can post some sample code....

Simon
 
Private Sub Command1_Click()

Dim sendmail, mail1

Dim EmailList

'Dim sendmail As Outlook.Application

EmailList = 'A@a.com;'

EmailList = EmailList & 'emaillist@jamaicanhomes.com'

Set sendmail = CreateObject("Outlook.Application")

Set mail1 = sendmail.CreateItem(0)

mail1.Subject = "Files found in directory :"

mail1.Recipients.Add ("dphilips@gleanerjm.com; gsegree@gleanerjm.com")

mail1.Body = "There was a total of This is a test don't worry! " & Count & " files found in the directory " & gDirPath & "." _

+ vbCr

mail1.Send

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top