PDA

View Full Version : How do I change the type of recipient of an automated email



Regouin
12-05-2005, 06:47 AM
Hello everyone,

I am struggling to set every recipient in a mail to BCC, i have created a listbox with mailadresses but obviously i dont want all the customers to see each others emailadresses so i am trying to set them all to bcc. Here is the code what i have, and i just cant find the command to set them to BCC.



Sub eMailDocument()


Dim AppOutlook As Outlook.Application
Dim OL As Object
Dim EmailItem As Object
Dim y As Long
Dim TempChar As String
Dim SaveName As String
Dim i As Long


Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
With EmailItem
.Subject = "U heeft post ontvangen in U HuurEenBox postbox."
.Body = "Beste HuurEenBox klant," & vbCrLf & vbCrLf & "Er is post voor u binnengekomen in uw HuurEenBox postbox. Deze kunt U afhalen bij het HuurEenBox filiaal in Aalsmeer." & vbCrLf & vbCrLf & "Met vriendelijke groet," & vbCrLf & "Het team van HuurEenBox."
For i = 0 To ListBox2.ListCount - 1
.Recipients.Add ListBox2.List(i, 0)
Next i
.Importance = olImportanceNormal 'Or olImportanceHigh Or olImportanceLow
On Error GoTo fout
.Send
End With

Application.ScreenUpdating = True
Set OL = Nothing
Set EmailItem = Nothing
MsgBox ("Rapport verzonden")
GoTo eind

fout:
MsgBox ("Outlook moet toestemming krijgen om de mail te kunnen versturen, verstuur bericht opnieuw.")
eind:
End Sub




please ignore the dutch in the msgboxes and mailbody

TIA
Frank

*edit*

i tried inserting this just after declaring the recipients but that doesnt seem to work

For Each recipient In .Recipients
Set .Type = olBCC
Next recipient


i also try to use a variable and dim that as a recipient but that generates the same error messages, i am quite lost with this atm.

TIA
frank

*edit*

Killian
12-05-2005, 07:35 AM
Hi Frank,

I noticed, AppOutlook is defined as Outlook.Application (implying early-binding, i.e. you have set a reference to the Microsoft Outlook Object Model), but isn't used and the other outlook objects are declared as objects and late-binding is used.
The reason I point this out is that if you haven't set a reference to the Microsoft Outlook Object Model, the Outlook constants you use won't have a value, so you'll need to use 0 for olMailItem and 3 for olBCC.

I've tested the following options in OL2003. Both produce an email with one "To" recipient and 4 "BCC" '#############################################################
'with a reference set to the Microsoft Outlook Object Model
Sub TestMailEarly()

Dim OL As Outlook.Application
Dim EmailItem As Outlook.MailItem
Dim newRecip As Outlook.Recipient
Dim i As Long

Set OL = New Outlook.Application
Set EmailItem = OL.CreateItem(olMailItem)
For i = 1 To 5
Set newRecip = EmailItem.Recipients.Add("Test " & i)
If i > 1 Then newRecip.Type = olBCC
Next i
EmailItem.Display

End Sub

'#############################################################
'WITHOUT a reference set to the Microsoft Outlook Object Model
Sub TestMailLate()

Dim OL As Object
Dim EmailItem As Object
Dim newRecip As Object
Dim i As Long

Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
For i = 1 To 5
Set newRecip = EmailItem.Recipients.Add("Test " & i)
If i > 1 Then newRecip.Type = 3
Next i
EmailItem.Display

End Sub