problem sending attachments???
-
Hello, I set up an email form, it works fine, with the exception of the attachments. It sends the email but not the attachment, when i remove the try catch i get the following error. Ill post the code below the error. ERROR: Invalid mail attachment 'C:\Documents and Settings\smariscal\My Documents\OliverGonzalez.doc' CODE: Sub btnSend_Click_1(sender As Object, e As EventArgs) Dim objMail As New MailMessage Dim objConn As SmtpMail Dim objAttach As MailAttachment dim postedFile = txtAttachment.PostedFile Dim strPath As String = "" Try strPath = Path.GetFullpath(postedFile.FileName) Catch End Try 'response.write(strPath) 'response.write(mappath("4.doc")) objMail.From = txtFrom.Text objMail.To = txtTo.Text objMail.Subject = txtSubject.Text objMail.Body = txtMessage.Text If ddlPriority.SelectedItem.Text = "Low" Then objMail.Priority = MailPriority.Low ElseIf ddlPriority.SelectedItem.Text = "Normal" Then objMail.Priority = MailPriority.Normal Else objMail.Priority = MailPriority.High End If objMail.Cc = txtCC.Text objMail.Bcc = TxtBCC.Text Try objAttach = New MailAttachment(strPath) objMail.Attachments.Add(objAttach) Catch End Try objConn.Send(objMail) End Sub THank you,
-
Hello, I set up an email form, it works fine, with the exception of the attachments. It sends the email but not the attachment, when i remove the try catch i get the following error. Ill post the code below the error. ERROR: Invalid mail attachment 'C:\Documents and Settings\smariscal\My Documents\OliverGonzalez.doc' CODE: Sub btnSend_Click_1(sender As Object, e As EventArgs) Dim objMail As New MailMessage Dim objConn As SmtpMail Dim objAttach As MailAttachment dim postedFile = txtAttachment.PostedFile Dim strPath As String = "" Try strPath = Path.GetFullpath(postedFile.FileName) Catch End Try 'response.write(strPath) 'response.write(mappath("4.doc")) objMail.From = txtFrom.Text objMail.To = txtTo.Text objMail.Subject = txtSubject.Text objMail.Body = txtMessage.Text If ddlPriority.SelectedItem.Text = "Low" Then objMail.Priority = MailPriority.Low ElseIf ddlPriority.SelectedItem.Text = "Normal" Then objMail.Priority = MailPriority.Normal Else objMail.Priority = MailPriority.High End If objMail.Cc = txtCC.Text objMail.Bcc = TxtBCC.Text Try objAttach = New MailAttachment(strPath) objMail.Attachments.Add(objAttach) Catch End Try objConn.Send(objMail) End Sub THank you,
For what it's worth here is some code I use.
Dim MyMessage As New MailMessage MyMessage.To = "" MyMessage.From = "" MyMessage.Subject = "" MyMessage.BodyFormat = MailFormat.Text MyMessage.Body = "Attached is a file" ''// ADD ATTACHMENT If File.Exists(Rpt) Then MyMessage.Attachments.Add(New System.Web.Mail.MailAttachment(Rpt)) Dim Smtp As SmtpMail Smtp.SmtpServer = "" Smtp.Send(MyMessage)
Hope that is helpful. Jason W.