我有一个工作的 vb.net,它会向收件人发送一封带有附件的电子邮件,其中还包含来自字段的数据。但我有两个问题:
- 即使我选择了多个文件,我也无法将多个文件附加到电子邮件中。
- 我希望能够查看我附加的内容,以便在必要时删除附件,然后再提交表单上的详细信息。
非常感谢您的帮助,谢谢。
我有一个附件按钮,您可以浏览它:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim openDLG As New OpenFileDialog
openDLG.AddExtension = True
openDLG.ReadOnlyChecked = True
openDLG.Multiselect = True
openDLG.Title = "Select the file(s) you want added to the message..."
openDLG.Filter = "All Files (*.*)|*.*"
If openDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
For Each item As String In openDLG.FileNames
'Create a new System.NET.Mail.Attachment class instance for each file.
attachToMsg = New System.Net.Mail.Attachment(item)
Next
MsgBox("I have finished adding all of the selected files! You can do more if you want!")
End If
然后我有一个提交按钮,它从表单发送所有信息,包括附件:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Using message As New MailMessage()
message.From = (New MailAddress(TextBox3.Text.ToString()))
message.[To].Add(New MailAddress("benjamin.boothe@experian.com"))
message.Subject = "New commission query"
message.Attachments.Add(attachToMsg)
Dim MsgBody As String
MsgBody = TextBox1.Text.ToString() & vbCr & _
TextBox2.Text.ToString() & vbCr & _
TextBox3.Text.ToString() & vbCr & _
ComboBox1.Text.ToString() & vbCr & _
ComboBox2.Text.ToString() & vbCr & _
ComboBox3.Text.ToString() & vbCr & _
ComboBox4.Text.ToString() & vbCr
message.Body = MsgBody
Dim client As New SmtpClient()
client.Host = "mailhost"
client.Send(message)
End Using
MessageBox.Show("Your request has been submitted!", "Congratulations!")
'close form
Me.Close()
End Sub
结束类
果酱