473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Send email with attachment from vb.net windows application

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
1 9245

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: m_evergreen | last post by:
Errors: An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll Additional information: Could not access 'CDO.Message' object. innerexception is "Exception has...
8
by: John Brock | last post by:
I am currently using a VB.NET program to send out e-mails with plain text bodies (plus one attachment). The emails are being received as Rich Text messages (probably just my personal Outlook...
5
by: Sean | last post by:
Hi... I want to use the macro/sendobject (or any other procedure) to send the contents of a table (very small, ~5 rows/columns) as an Outlook message body, not as an attachment. Access 2000 will...
3
by: sentiboy | last post by:
I am using the following code for sending email through mapi in VS 2005 environment: Public objSession As New MSMAPI.MAPISession Public objMessage As New MSMAPI.MAPIMessages ...
3
by: =?Utf-8?B?SHVnaA==?= | last post by:
Hi There, I use follow code to send email inside VB.NET 2005. It does not work well. Error message of "Failure sending email" would occue. However, email was sent out sometimes. I am confused...
5
by: Ben K | last post by:
I saw some posting some time ago regarding a "trick" to automatically pop up an email editor with attachment using the default mail client. It is basically using automation to do the following...
1
by: Chitu03 | last post by:
Hi I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know how can i get from database and then add to my mail....
1
by: maxxxxel | last post by:
Hi Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine. Our problem is that when we send...
1
by: sxwend | last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the results to just the email addresses that the query...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.