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

Sending multiple E-Mails using MAPI

Status
Not open for further replies.

Muzzery

Programmer
Jan 11, 2002
72
GB
I'm using VBA and Access to send E-Mails through Outlook. this is the code that i am using.



code:--------------------------------------------------------------------------------
objMessage.Subject = Me![e-mail subject]
objMessage.Text = Me![e-mail text]
Set objRecipient = objMessage.Recipients.Add
objRecipient.Name = Me![E-mail address]
objRecipient.Resolve
objMessage.Send ShowDialog:=True
objSession.Logoff
--------------------------------------------------------------------------------


In outlook, to send to multiple recievers of an E-Mail, Outlook uses a semi-colon ( to seperate the E-Mail addresses.

What i want to do is send an e-mail to multiple addresses, in the To command of the E-Mail "objRecipient.Name"

In the field that the code takes the Address from, i want to be able to have me@me.com; you@you.com and it send to both those E-Mail addresses.

Does this make sense

if it does, is it possible?

Thanks

Muzz
 
Obviously I'm not quite sure what context your code is in, but an alternative method would be to use:

DoCmd.SendObject [objecttype][, objectname][, outputformat][, to][, cc][, bcc][, subject][, messagetext][, editmessage][, templatefile]

where "to" can be a list of comma separated recipients.

Hope this helps
 
Thanks for the Advice MissTipps, but the problem is that i need to send an attathcment with the e-mail, and using the default DoCmd.SendObject, this isn;t possible, so i'm having to set up objects like this:

Set objSession = CreateObject("mapi.session")

and then doing this:

Set objMessage = objSession.Outbox.Messages.Add


and then continuing the code as above. I've looked on MSDN, and i've found this command:

objRecipients.AddMultiple

but the trouble is that it doesn't work, could anybody point me in the right direction, or tell me how to use this command properly? I'm at a loss with this problem.

Thanks

Muzz
 
Thanks MissTips, but i still can't get this to work, this is what i have put in:

-------------------------

Sub MicroSoftExample(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(Me![E-mail address])
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
'Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
'objOutlookRecip.Type = olCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "Last test - I promise." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub

----------------------------

the me![e-mail address] returns this value:

me@me.com; you@you.com; them@them.com

etc.

All this does is out that into the "to" box, but only sends it to the last name, and put's the first few as the Name of the recipient.

I have no idea how to get round this. I'm completely stuck, could you help?

Muzz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top