[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
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
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.
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
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?
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
Re: [2008] mail attachment
Re: [2008] mail attachment
ok, but i think , it's because it use the media type, octet-stream? is it correct?
Re: [2008] mail attachment
i found the problem, the code should be
vb Code:
fileatt.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable
thx
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?
Re: [RESOLVED] [2008] mail attachment
well, the problem was SevenBit only accepted txt files only. But QuotedPrintable accept any printable things