Running Outlook from VB with multiple email addresses [migrated]
- by Mac
I am sending emails from my VB6 system and I am having problems with sending a single email to various email addresses. The code is as follows:
On Error Resume Next
Err.Clear
Set oOutLookObject = CreateObject("Outlook.Application")
If Err <> 0 Then
MsgBox "Email error. Err = " & Err & " Description = " & Err.Description
EmailValid = "N"
Exit Function
End If
Set oEmailItem = oOutLookObject.CreateItem(0)
If Err <> 0 Then
MsgBox "Email error. Err = " & Err & " Description = " & Err.Description
EmailValid = "N"
Exit Function
End If
With oEmailItem
.Recipients.Add (SMRecipients)
.Subject = SMSubject
.Importance = IMPORTANCENORMAL
.Body = SMBody
For i = 1 To 10
If RTrim(SMAttach(i)) <> "" Then
.attachments.Add SMAttach(1) 'i)
Else
Exit For
End If
Next i
.send
End With
If Err <> 0 Then
MsgBox "Email error. Err = " & Err & " Description = " & Err.Description
EmailValid = "N"
Exit Function
End If
''' .Attachments.Add ("c:\temp\test2.txt")
Set oOutLookObject = Nothing
I have set SMRecipients to a single email address and it is fine but when I add more addresses seperated by semicolons or spaces it only sends to the original address.
My system runs under XP.
Another point is that it use to find the addresses in the Outlook Address book and where they wetre not specific enough it would display the matching addresses for selection of the correct one. It no longer does this.