send email with attachment

i have a little form to submit an email that works.
I need to add an option for users to attach .doc or .pdf files and send them as attachement with this form.
I am getting an error : Invalid mail attachment ....

in my aspx file I have:
<input id="txtFile" type="file" runat="server" size="32" NAME="txtFile">

in aspx.vb

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            Dim objMail As New MailMessage
            objMail.From = "server_email@domain.com"
            objMail.To = "my_email@domain.com " 
            objMail.Subject = Request.Form("txtSubject")
            objMail.BodyFormat = MailFormat.Html
         
            objMail.Body = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbCrLf _
                & "<body>" & vbCrLf _
                & " <h2>Message </h2>" & vbCrLf _
               & "</body>" & vbCrLf _
                & "</html>" & vbCrLf

            SmtpMail.SmtpServer = "199.166.10.111"
            If Not (txtFile.PostedFile Is Nothing) Then

                MAtt = New MailAttachment(txtFile.PostedFile.FileName)

                objMail.Attachments.Add(MAtt)
            End If

            SmtpMail.Send(objMail)
           Response.Redirect("confirm.aspx")
        Catch ex As Exception
            lblError.Text = ex.Message
            lblError.Visible = True

        End Try

    End Sub


thank you,
ainaks25Asked:
Who is Participating?
 
ee_ai_constructCommented:
Closed, 200 points refunded.
ee_ai_construct
Community Support Moderator
replacement part #xm34
0
 
TertioptusCommented:
Check here:  Consider using the SMTP namespace
http://www.codeproject.com/vb/net/SendMail.asp
0
 
bchoorCommented:
if ur running .NET 2.0, MailAttachment is now obsolete try using this instead

Dim data As New Attachment(fileName, MediaTypes.Application.Octet)

Dim disposition As ContentDisposition = data.ContentDisposition

disposition.CreationDate = System.IO.File.GetCreationTime(fileName)
disposition.ModificationDate = System.IO.File.GetLastWriteTime(fileName)
disposition.ReadDate = System.IO.File.GetLastAccessTime(fileName)

objMail.Attachments.Add(data)


you can see a more detailed sample from here: http://msdn2.microsoft.com/en-us/library/system.net.mail.attachment.aspx


make sure u import system.net.mail

HTH
~BC
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ainaks25Author Commented:
both of them somehow don't work for me.
0
 
ainaks25Author Commented:
0
 
bchoorCommented:
hmmm....got it - ur attached file needed to be uploaded to the server. Well, glad you figured it out.

~BC
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.