|
-
Jul 15th, 2008, 03:53 AM
#1
Thread Starter
Frenzied Member
[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:
Imports System.Net
Imports System.Net.Mail
Dim msg As New MailMessage(EmailFromTextBox.Text, EmailToTextBox.Text, EmailSubjectTextBox.Text, EmailBodyTextBox.Text)
msg.IsBodyHtml = True
StatusLabel.Visible = False
Try
Dim client As New SmtpClient("smtp.gmail.com", 587)
client.EnableSsl = True
client.UseDefaultCredentials = false
client.Credentials = loginInfo
client.Send(msg)
Catch ex As SmtpException
StatusLabel.Visible = True
StatusLabel.Style.Add("color", "#CC0033")
StatusLabel.Text = "The following error occurred: " + "<br /><br />" + ex.Message
Return
End Try
StatusLabel.Visible = True
StatusLabel.Style.Add("color", "#009966")
StatusLabel.Text = "Email sent successfully."
thx
-
Jul 15th, 2008, 04:58 AM
#2
Fanatic Member
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
-
Jul 15th, 2008, 09:56 AM
#3
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.
-
Jul 15th, 2008, 04:35 PM
#4
Thread Starter
Frenzied Member
Re: [2008] mail attachment
hi
vb Code:
karthikeyan: I used ur code with file upload like this: Dim fileatt As New Attachment(FileUpload1.PostedFile.FileName.ToString) fileatt.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit 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
-
Jul 16th, 2008, 03:40 AM
#5
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?
-
Jul 17th, 2008, 12:27 PM
#6
Thread Starter
Frenzied Member
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
-
Jul 17th, 2008, 12:35 PM
#7
Re: [2008] mail attachment
-
Jul 17th, 2008, 12:47 PM
#8
Thread Starter
Frenzied Member
Re: [2008] mail attachment
ok, but i think , it's because it use the media type, octet-stream? is it correct?
-
Jul 17th, 2008, 12:48 PM
#9
Thread Starter
Frenzied Member
Re: [2008] mail attachment
i found the problem, the code should be
vb Code:
fileatt.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable
thx
-
Jul 18th, 2008, 11:41 AM
#10
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?
-
Jul 18th, 2008, 02:23 PM
#11
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|