Send email with attachment from vb.net windows application

S

shil

Hi,

I'm using FW 2.0 to send an email with an attachment using
System.Net.Mail class. If I try to attach a file from my file system,
I could successfully send the eamil. But I need to generate a report
on the fly and send an email with that report as an attachment. Here
is the code I have.

-----------------------------------------------------------
Dim Server as string, File as string
Dim mailClient As SmtpClient = New SmtpClient()
Dim msgFrom As String, msgTo As String, msgBody As String, msgSubject
As String

msgFrom = "(e-mail address removed)"
msgTo = "(e-mail address removed)"
msgSubject = "Your Report"
msgBody = "Attached is your report:"

Dim msg As New Net.Mail.MailMessage(msgFrom, msgTo, msgSubject,
msgBody)

mailClient.UseDefaultCredentials = True
mailClient.Host = "SMTPServer"
mailClient.Port = "25"

Server = "http://MyServer/Root/"
File = Server & "GenerateReport.aspx?ReportID=1"

msg.Attachments.Add(New Attachment(File, "text/plain"))

mailClient.Send(msg)
--------------------------------------------------------

When I execute the above code, I get an error "URI formats are not
supported."
But if I attach a file from my file system, it works fine.

Can any one direct me in a right direction?

Thanks.
 
S

sloan

Server = "http://MyServer/Root/"
File = Server & "GenerateReport.aspx?ReportID=1"


That's not a file (like "C:\myfile.txt")
That's a URL.


If you want to do that, I think you have to use the http classes , and write
the url results to a file.


Do a search for "screen scraping", and you'll see how that is done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top