I know this is an old issue or concern but can you help me on this.
I have a source code found in the internet that can send an attachment via email. I tried it in my application but I getting this error.
System.Web.HttpException (0x8000405) Invalid mail attachment C:File.pdf
at System.Web.Mail.MailAttachment.VerifyFile()
at System.Web.Mail.Attachment..ctor(String filename)
This is the code I found
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Web.Mail
Public Class ReportsForm
Dim cryRpt As New ReportDocument
Dim pdfFile As String = "C:File.pdf"
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
cryRpt.Load("Crystal Report Path here")
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New _
DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions
CrDiskFileDestinationOptions.DiskFileName = pdfFile
CrExportOptions = cryRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
cryRpt.Export()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
sendMail()
End Sub
Private Sub sendMail()
Try
Dim Smtp As SmtpMail
SmtpMail.SmtpServer.Insert(0, "hostname")
Dim Msg As MailMessage = New MailMessage
Msg.To = "to address"
Msg.From = "from address"
Msg.Subject = "Crystal Report Attachment "
Msg.Body = "Crystal Report Attachment "
Msg.Attachments.Add(New MailAttachment(pdfFile))
SmtpMail.Send(Msg)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Thank you
question from:https://stackoverflow.com/questions/65886531/sending-email-with-attachment-using-vb-net