Wondering if there is a way to email a pdf file. What I am trying to do is allow the user to fill out the textboxes and attach a pdf file and hit the send button to email these back to me.
I have two buttons on my form. One takes the inputs from textboxes and emails them. The other lets the user browse and load a pdf file and loads it using the webBrowser control which I have the visability set to false.
What I am trying to do is add code to the button that sends the email that will also send the pdf file from the webBrowser control.
Am I trying to go about this the wrong way? Here is the code that I have for the button that sends the email. Thanks for any help.
Dim mymailmsg As New MailMessage
Dim a As String = TextBox5.Text
Dim b As String = TextBox1.Text
Dim c As String = TextBox2.Text
Dim d As String = TextBox3.Text
Dim f As String = TextBox4.Text
Dim g As String = TextBox6.Text
Try
mymailmsg.From = New MailAddress(xxxx@gmail.com")
mymailmsg.To.Add(xxx@aol.com")
mymailmsg.Subject = "Waste Report"
mymailmsg.Body = a & vbCrLf & b & vbCrLf & c & vbCrLf & d & vbCrLf & f & vbCrLf & g
Dim smtp As New SmtpClient("smtp.gmail.com")
smtp.Port = 587
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential("xxxx@gmail.com", "password")
smtp.Send(mymailmsg)
MsgBox("Sent")
Catch ex As Exception
End Try
And the code for the button that lets the user browse and load the pdf file
Dim OpenFileDialog1 As New OpenFileDialog()
Dim Response As DialogResult
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "PDF Files(*.pdf)|*.pdf|All Files(*.*)|*.*"
Response = OpenFileDialog1.ShowDialog()
If Response <> Windows.Forms.DialogResult.Cancel Then
If OpenFileDialog1.FileName <> "" Then
WebBrowser1.Navigate(OpenFileDialog1.FileName)
End If
End If
End Sub
I have two buttons on my form. One takes the inputs from textboxes and emails them. The other lets the user browse and load a pdf file and loads it using the webBrowser control which I have the visability set to false.
What I am trying to do is add code to the button that sends the email that will also send the pdf file from the webBrowser control.
Am I trying to go about this the wrong way? Here is the code that I have for the button that sends the email. Thanks for any help.
Dim mymailmsg As New MailMessage
Dim a As String = TextBox5.Text
Dim b As String = TextBox1.Text
Dim c As String = TextBox2.Text
Dim d As String = TextBox3.Text
Dim f As String = TextBox4.Text
Dim g As String = TextBox6.Text
Try
mymailmsg.From = New MailAddress(xxxx@gmail.com")
mymailmsg.To.Add(xxx@aol.com")
mymailmsg.Subject = "Waste Report"
mymailmsg.Body = a & vbCrLf & b & vbCrLf & c & vbCrLf & d & vbCrLf & f & vbCrLf & g
Dim smtp As New SmtpClient("smtp.gmail.com")
smtp.Port = 587
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential("xxxx@gmail.com", "password")
smtp.Send(mymailmsg)
MsgBox("Sent")
Catch ex As Exception
End Try
And the code for the button that lets the user browse and load the pdf file
Dim OpenFileDialog1 As New OpenFileDialog()
Dim Response As DialogResult
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "PDF Files(*.pdf)|*.pdf|All Files(*.*)|*.*"
Response = OpenFileDialog1.ShowDialog()
If Response <> Windows.Forms.DialogResult.Cancel Then
If OpenFileDialog1.FileName <> "" Then
WebBrowser1.Navigate(OpenFileDialog1.FileName)
End If
End If
End Sub