send email with attachment

Posted on 2006-06-06
Last Modified: 2010-04-23
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
            Dim objMail As New MailMessage
            objMail.From = ""
            objMail.To = " "
            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 = ""
            If Not (txtFile.PostedFile Is Nothing) Then

                MAtt = New MailAttachment(txtFile.PostedFile.FileName)

            End If

        Catch ex As Exception
            lblError.Text = ex.Message
            lblError.Visible = True

        End Try

    End Sub

thank you,
Question by:ainaks25
    LVL 5

    Expert Comment

    Check here:  Consider using the SMTP namespace
    LVL 10

    Expert Comment

    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)


    you can see a more detailed sample from here:

    make sure u import


    Author Comment

    both of them somehow don't work for me.

    Author Comment

    LVL 10

    Expert Comment

    by:bchoor it - ur attached file needed to be uploaded to the server. Well, glad you figured it out.


    Accepted Solution

    Closed, 200 points refunded.
    Community Support Moderator
    replacement part #xm34

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now