我在vb.net中遇到一个列表时遇到了一些麻烦。
基本上我要做的是发送电子邮件,用户可以从4个选项中选择发送抄送。我开始用一系列if语句检查是否检查了一个复选框,如果是,那么它将它添加到CC,但这似乎只添加了一个。所以我创建了ccList,其想法是创建一个字符串列表并将其添加到cc中。我不确定它是否会起作用,但如果我在第二个,第三个或第四个中添加一个中断,它不会落入它并且只会通过第一个(如果每个复选框都为真)。如果我只检查一个,那么它就属于那个。
If FSEmailAddress <> "" Then
Dim OutlookMessage As outlook.MailItem
Dim AppOutlook As New outlook.Application
Dim ccList As List(Of String) = Nothing
Try
OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
Dim Recipents As outlook.Recipients = OutlookMessage.Recipients
Recipents.Add(FSEmailAddress)
If email1.Checked = True Then
ccList.Add("email1@some.email.com")
End If
If email2.Checked = True Then
ccList.Add("email2@some.email.com; ")
End If
If email3.Checked = True Then
ccList.Add("email3@some.email.com; ")
End If
If email4.Checked = True Then
ccList.Add("email4@some.email.com; ")
End If
OutlookMessage.CC = ccList.ToString
OutlookMessage.Subject = responseVIN.Text & " was sent back to you by " & GetUserName()
'link = archive_dir & responseVIN.Text
OutlookMessage.Body = responseVIN.Text & " was returned To you" & vbCrLf & "Navigate To the following location To view the comments In the ReadMe file:" & vbCrLf & vbCrLf & archive_dir & responseVIN.Text & vbCrLf & vbCrLf & resAdvice.Text
OutlookMessage.BodyFormat = outlook.OlBodyFormat.olFormatHTML
OutlookMessage.Send()
答案 0 :(得分:1)
对任何感兴趣的人:
以下是我遇到的两个问题的解决方案:
Dim FSEmailAddress As String = ""
Dim link As String = ""
Dim ccJoin As String = ""
If FSEngineerName = "Email 1" Then
FSEmailAddress = "email1@some.email.com"
ElseIf FSEngineerName = "Email 2" Then
FSEmailAddress = "email2@some.email.com"
ElseIf FSEngineerName = "Email 3" Then
FSEmailAddress = "email3@some.email.com"
ElseIf FSEngineerName = "Email 4" Then
FSEmailAddress = "email4@some.email.com"
End If
If FSEmailAddress <> "" Then
Dim OutlookMessage As outlook.MailItem
Dim AppOutlook As New outlook.Application
Dim ccList As New List(Of String)
Try
OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
Dim Recipents As outlook.Recipients = OutlookMessage.Recipients
Recipents.Add(FSEmailAddress)
If email1.Checked Then
ccList.Add("email1@some.email.com")
End If
If email2.Checked Then
ccList.Add("email2@some.email.com; ")
End If
If email3.Checked Then
ccList.Add("email3@some.email.com; ")
End If
If email4.Checked Then
ccList.Add("email4@some.email.com; ")
End If
ccJoin = String.Join("; ", ccList.ToArray())
OutlookMessage.CC = ccJoin
OutlookMessage.Subject = responseVIN.Text & " was sent back to you by " & GetUserName()
OutlookMessage.Body = responseVIN.Text & " was returned To you" & vbCrLf & "Navigate To the following location To view the comments In the ReadMe file:" & vbCrLf & vbCrLf & archive_dir & responseVIN.Text & vbCrLf & vbCrLf & resAdvice.Text
OutlookMessage.BodyFormat = outlook.OlBodyFormat.olFormatHTML
OutlookMessage.Send()
Catch ex As Exception
MessageBox.Show("Mail could Not be sent")
Finally
OutlookMessage = Nothing
AppOutlook = Nothing
End Try
End If