Results 1 to 11 of 11

Thread: [RESOLVED] [2008] mail attachment

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Resolved [RESOLVED] [2008] mail attachment

    hello, i would to attach file to my mail, and the file path to my mail is on a textbox. I would like to know how i can tell it, that the filepath to be attached is the text on the textbox. i tried with textb.text, but it saysit's not a valid... .attachment

    asp Code:
    1. Imports System.Net
    2. Imports System.Net.Mail
    3.  
    4. Dim loginInfo As New NetworkCredential("[email protected]", "yourGMailPassword")
    5. Dim msg As New MailMessage(EmailFromTextBox.Text, EmailToTextBox.Text, EmailSubjectTextBox.Text, EmailBodyTextBox.Text)
    6. msg.IsBodyHtml = True
    7. StatusLabel.Visible = False
    8.  
    9. Try
    10.     Dim client As New SmtpClient("smtp.gmail.com", 587)
    11.     client.EnableSsl = True
    12.     client.UseDefaultCredentials = false
    13.     client.Credentials = loginInfo
    14.     client.Send(msg)
    15. Catch ex As SmtpException
    16.     StatusLabel.Visible = True
    17.     StatusLabel.Style.Add("color", "#CC0033")
    18.     StatusLabel.Text = "The following error occurred: " + "<br /><br />" + ex.Message
    19.     Return
    20. End Try
    21.  
    22.     StatusLabel.Visible = True
    23.     StatusLabel.Style.Add("color", "#009966")
    24.     StatusLabel.Text = "Email sent successfully."

    thx

  2. #2
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    Re: [2008] mail attachment

    hi mate.

    Try this

    Code:
    Dim fileatt As New Attachment(filePath) 
    
    fileatt .TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit 
    
    message.Attachments.Add(fileatt ) 
    
    client.Send(msg)
    good luck
    Loving dotnet

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] mail attachment

    You must use the File Upload Control, not a textbox. The file then gets uploaded as part of the request, so you need to look at filecontrol.PostedFile is not null. Then process the stream (save to disk) and then attach it.

  4. #4

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: [2008] mail attachment

    hi

    vb Code:
    1. karthikeyan: I used ur code with file upload like this:
    2.  
    3.  Dim fileatt As New Attachment(FileUpload1.PostedFile.FileName.ToString)
    4.  
    5.         fileatt.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit
    6.  
    7.         msg.Attachments.Add(fileatt)

    it does sent the file, i tried with an gif image it sent it, but when i open i i'm not able to see the pic, it says dwg faild. What should be the problem?

    thx

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] mail attachment

    My guess is that you sent a 0 byte file. Did you check to see if PostedFile existed? What does your form look like? What does all of your code look like?

  6. #6

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: [2008] mail attachment

    well, it works perfect with a txt file.
    Do i need to type some other code for posted file?
    i just put the uploadfile box then on the code i wrote, the code on my last post

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

  8. #8

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: [2008] mail attachment

    ok, but i think , it's because it use the media type, octet-stream? is it correct?

  9. #9

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: [2008] mail attachment

    i found the problem, the code should be

    vb Code:
    1. fileatt.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable

    thx

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] [2008] mail attachment

    When it wasn't working, you said that it worked only for .txt files but not other file extensions. What was happening in those cases?

  11. #11

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: [RESOLVED] [2008] mail attachment

    well, the problem was SevenBit only accepted txt files only. But QuotedPrintable accept any printable things

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width