Link to home
Start Free TrialLog in
Avatar of Euro5
Euro5Flag for United States of America

asked on

VBA sending mail to multiple recipients

I have a code that is working well but I can't figure out how to send to multiple ToAddress
I tried the following, but just get an error.

ToAddress = "firstemail@gmail.com;secondemail@gmail.com"

Open in new window


This works for only one recipient:
Const PR_ATTACH_MIME_TAG = "http://schemas.microsoft.com/mapi/proptag/0x370E001E"
Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001E"
Const PR_ATTACHMENT_HIDDEN = "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B"

Sub testing2()
Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MyTime
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
Dim realAttachment
MyTime = Now

ToAddress = "firstemail@gmail.com"
MessageSubject = "Auto Stats " & MyTime
MessageBody = "Good Morning" & vbCrLf & "Produced at " & MyTime
MessageAttachment = "D:\1.png"
Set ns = Outlook.GetNamespace("MAPI")
Set newMail = Outlook.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody
newMail.Recipients.Add (ToAddress)
Set realAttachment = newMail.Attachments.Add(MessageAttachment)
Set oPA = realAttachment.PropertyAccessor
oPA.SetProperty PR_ATTACH_MIME_TAG, "image/png"
oPA.SetProperty PR_ATTACH_CONTENT_ID, "myident" 'change myident for another other image
newMail.HTMLBody = newMail.HTMLBody & "<IMG align=baseline border=0 hspace=0 src=cid:myident>" 'need to match the "myident" above
newMail.Send
End Sub

Open in new window

Avatar of Kimputer
Kimputer

ToAddress = "firstemail@gmail.com"
newMail.Recipients.Add (ToAddress)
ToAddress = "secondemail@gmail.com"
newMail.Recipients.Add (ToAddress) 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Euro5
Euro5
Flag of United States of America image

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