フィールドからのデータも添付して受信者に電子メールを送信するvb.netが機能しています。しかし、私には2つの問題があります:
- 複数のファイルを選択しても、複数のファイルをメールに添付できません。
- フォームに詳細を送信する前に、必要に応じて添付ファイルを削除できるように、添付ファイルを確認できるようにしたいと思います。
どうぞよろしくお願いいたします。
参照できる添付ファイル ボタンがあります。
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
クラス終了
ジャムマン