By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,813 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,813 IT Pros & Developers. It's quick & easy.

Send email with attachment from vb.net windows application

P: n/a
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 = "me@mycompany.com"
msgTo = "me@mycompany.com"
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.

May 11 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a

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.


"shil" <jo******@gmail.comwrote in message
news:11*********************@l77g2000hsb.googlegro ups.com...
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 = "me@mycompany.com"
msgTo = "me@mycompany.com"
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.

May 11 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.