[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

send email with attachment

Posted on 2006-06-06
6
Medium Priority
?
250 Views
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
        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,
0
Comment
Question by:ainaks25
6 Comments
 
LVL 5

Expert Comment

by:Tertioptus
ID: 16843970
Check here:  Consider using the SMTP namespace
http://www.codeproject.com/vb/net/SendMail.asp
0
 
LVL 10

Expert Comment

by:bchoor
ID: 16844274
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
 

Author Comment

by:ainaks25
ID: 16844910
both of them somehow don't work for me.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

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

~BC
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 16865765
Closed, 200 points refunded.
ee_ai_construct
Community Support Moderator
replacement part #xm34
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

872 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