Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. problem sending attachments???

problem sending attachments???

Scheduled Pinned Locked Moved ASP.NET
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hounetdev
    wrote on last edited by
    #1

    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,

    J 1 Reply Last reply
    0
    • H hounetdev

      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,

      J Offline
      J Offline
      Jason Weibel
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups