使用多个电子邮件地址从VB运行Outlook



我正在从我的 VB6 系统发送电子邮件,但在向不同的电子邮件地址发送一封电子邮件时遇到问题。 代码如下:

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:temptest2.txt")
Set oOutLookObject = Nothing

我已经将SMRecipients设置为一个电子邮件地址,这很好,但是当我添加更多由分号或空格分隔的地址时,它只会发送到原始地址。

我的系统在XP下运行。

另一点是,它用于查找Outlook通讯簿中的地址,并且它们不够具体的地方,它将显示匹配的地址以选择正确的地址。 它不再这样做。

使用 .Recipients.Add() 时,您需要自己拆分收件人,将每个收件人传递给.Add()

Dim RecipientList() As String
Dim RecipientString As String
Recipients = Split(SMRecipients, ";")
For Each RecipientString in Recipients
  .Recipients.Add RecipientString
Next

最新更新