Vb.net 您告诉我们的所有内容或包含整个代码(而不仅仅是添加地址的位置,因为发送部分起作用)。@David该邮件有许多收件人。@Varocbas:多次包含相同的收件人?我认为邮件服务器会足够聪明来纠正这个问题。如果没有,只将收件人过滤到不同的电子邮件地址似乎很简单。

Vb.net 您告诉我们的所有内容或包含整个代码(而不仅仅是添加地址的位置,因为发送部分起作用)。@David该邮件有许多收件人。@Varocbas:多次包含相同的收件人?我认为邮件服务器会足够聪明来纠正这个问题。如果没有,只将收件人过滤到不同的电子邮件地址似乎很简单。,vb.net,Vb.net,您告诉我们的所有内容或包含整个代码(而不仅仅是添加地址的位置,因为发送部分起作用)。@David该邮件有许多收件人。@Varocbas:多次包含相同的收件人?我认为邮件服务器会足够聪明来纠正这个问题。如果没有,只将收件人过滤到不同的电子邮件地址似乎很简单。@David老实说,我不确定这个问题是否会自动更正。但是我假设这段代码运行得很好(OP并没有抱怨它运行得很好),而没有分析确切的原因(每次都会发送不同的电子邮件,或者甚至同一个用户可能有不同的地址,或者这个函数被多次调用?)。我评论的全部要点是


您告诉我们的所有内容或包含整个代码(而不仅仅是添加地址的位置,因为发送部分起作用)。@David该邮件有许多收件人。@Varocbas:多次包含相同的收件人?我认为邮件服务器会足够聪明来纠正这个问题。如果没有,只将收件人过滤到不同的电子邮件地址似乎很简单。@David老实说,我不确定这个问题是否会自动更正。但是我假设这段代码运行得很好(OP并没有抱怨它运行得很好),而没有分析确切的原因(每次都会发送不同的电子邮件,或者甚至同一个用户可能有不同的地址,或者这个函数被多次调用?)。我评论的全部要点是强调只调用一次
message.Send()
在这里并不重要。
 Private Sub SendEmails()
    Try

        Dim message As New PCA.Core.Messaging.Message(PCA.Core.Messaging.MessageTypes.JumperLog)
        'Dim distLists As List(Of PCA.Core.DistributionList) = (From r In Trident.Core.Globals.TridentApp.ApplicationCache.DistributionLists.DistributionLists Where r.ID.Contains("JL_")).ToList
        Dim distLists As List(Of PCA.Core.DistributionList) = (From r In PCA.Core.DistributionList.GetDistributionLists Where r.Id.Contains("JL_")).ToList

        For Each distlist As PCA.Core.DistributionList In distLists
            Dim recipients As System.Collections.Generic.List(Of Trident.Core.User)
            recipients = Trident.Core.Core.Message.GetTridentDistributionList("TRIMAINT", distlist.Id)

            If recipients.Count > 0 Then
                message.Recipients.AddRange(recipients)
            End If

        Next

        If message.Recipients.Count = 0 Then Exit Sub

        Dim ds As New DataSet
        Dim dbConn As New Trident.Core.DBConnection
        Dim sql As String = "SELECT * FROM ***.Maintenance.JumperLogs WHERE Removed <> 1 AND Plant = @Plant ORDER BY InstallDate "
        dbConn("@Plant") = Trident.Core.Globals.TridentApp.DefaultPlant.Plant

        Dim tmpJL As Trident.Objects.Maintenance.JumperLogs.JumperLog
        message.Subject = "Jumper Log - Active Jumpers"
        ds = dbConn.FillDataSet(sql)
        If ds.Tables(0).Rows.Count = 0 Then Exit Sub
        For Each dr As DataRow In ds.Tables(0).Rows
            tmpJL = New Trident.Objects.Maintenance.JumperLogs.JumperLog(dr)

            message.Body += "Jumper Log # " & tmpJL.LogId & " - Installed: " & tmpJL.InstallDate & vbCrLf

            message.Body += "Mill: " & Trident.Core.Globals.TridentApp.DefaultPlant.Description & vbCrLf
            message.Body += "Facility: " & tmpJL.FacilityObject.Description & vbCrLf
            If Not tmpJL.MachineAreaObject Is Nothing Then
                message.Body += "Area: " & tmpJL.MachineAreaObject.Description & vbCrLf
            End If
            If Not tmpJL.LocationObject Is Nothing Then
                message.Body += "Location: " & tmpJL.LocationObject.Description & vbCrLf
            End If
            If Not tmpJL.EquipmentObject Is Nothing Then
                message.Body += "Equipment: " & tmpJL.EquipmentObject.Description & vbCrLf
            End If

            message.Body += "Installed  By: " & tmpJL.InstalledBy.FullName & vbCrLf
            'message.Body += "Install Date: " & tmpJL.InstallDate & vbCrLf
            message.Body += "Tag: " & tmpJL.Tag & vbCrLf
            message.Body += "Tag Attached To: " & tmpJL.TagAttachedTo & vbCrLf
            message.Body += "Work Order: " & tmpJL.WorkOrder & vbCrLf
            message.Body += vbCrLf
            message.Body += "Reason: " & tmpJL.Reasons.ToUpper & vbCrLf
            message.Body += vbCrLf
            message.Body += "---------------------------------------------------------------------------------------------------------------------------------------------------" & vbCrLf
            message.Body += vbCrLf


        Next

        message.Send()


    Catch ex As Exception
        Throw New PCA.Core.Exceptions.PCAErrorException(ex)
    End Try

End Sub