Hier vielleicht nochmal der Code (abgespeckt) hinter dem Button.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim Path As String
Dim name As String
Dim vorname As String
Dim re_nr As String
Dim date_time_now As String
Dim email As String
Dim nr_adresse As String
Dim datum_rechnung As String
Dim titel As String
Dim anrede As String
date_time_now = Replace(System.DateTime.Now, ":", "_")
date_time_now = Replace(date_time_now, " ", "_")
name = fo_patientenrechnung_einzel.Firma_nameTextBox.Text
vorname = fo_patientenrechnung_einzel.VornameTextBox.Text
re_nr = fo_patientenrechnung_einzel.nr_id_rechnungTextBox.Text
nr_adresse = fo_patientenrechnung_einzel.Id_adresseTextBox.Text
email = fo_patientenrechnung_einzel.emailTextBox.Text
datum_rechnung = fo_patientenrechnung_einzel.DatumDateTimePicker.Text
titel = fo_patientenrechnung_einzel.titeltextbox.Text
anrede = fo_patientenrechnung_einzel.anredeTextBox.Text
Dim di As DirectoryInfo = Directory.CreateDirectory(Ablagepfad.Pfad + "\" + name + "_" + vorname)
Path = Ablagepfad.Pfad + "\" + name + "_" + vorname + "\" + "Rechnung_" + re_nr + "-" + nr_adresse + "_" + datum_rechnung + "_" + date_time_now + ".pdf"
Dim deviceInfo As String = ""
Dim mimType As String = ""
Dim encoding As String = ""
Dim fileNameExt As String = ""
Dim streamsPDF() As String = Nothing
Dim warnings() As Microsoft.Reporting.WinForms.Warning = Nothing 'This is for PDF
Dim bytes() As Byte = Nothing
Dim fPath As String = Path
Dim fileSW As System.IO.FileStream 'This is for PDF
bytes = ReportViewer1.LocalReport.Render("PDF", deviceInfo, mimType, encoding, fileNameExt, streamsPDF, warnings)
fileSW = New System.IO.FileStream(fPath, IO.FileMode.Create)
fileSW.Write(bytes, 0, bytes.Length)
fileSW.Flush()
fileSW.Close()
Dim EmailMessage As New MailMessage()
Dim Anhang As String = Path
Try
EmailMessage.From = New MailAddress("karlheinz@hotmail.com")
EmailMessage.To.Add(fo_patientenrechnung_einzel.emailTextBox.Text)
EmailMessage.Subject = "Ihre Rechnung " & re_nr & "/" & nr_adresse
EmailMessage.Body = LTrim(LTrim(anrede & " ") & LTrim(titel & " ") & LTrim(name & ",")) & vbCrLf & vbCrLf & "In der Anlage erhalten Sie die Rechnung Nr.: " & re_nr & "/" & nr_adresse & "." & vbCrLf & vbCrLf & "Mit freundlichen Grüßen" & vbCrLf & vbCrLf & "KarlHeinz" & vbCrLf & vbCrLf & "Tel.: " + "xxxxxx" & vbCrLf & "Fax: " + "xxxxxxx" & vbCrLf & "Mail: " + "karlheinz@hotmail.com" & vbCrLf & "www.karlheinz.de"
EmailMessage.Attachments.Add(New System.Net.Mail.Attachment(Anhang))
Dim SMTP As New SmtpClient("smtp-mail.outlook.com")
SMTP.Port = 587
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("karlheinz@hotmail.com", "passwort")
SMTP.Send(EmailMessage)
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
End Sub