473,895 Members | 2,286 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading and sending a file in email ?

I would like to build a windows app or service that would read a .txt
file and than put the contents of that file in an email and send off
the email. WOuld that be very difficult?...ho w could this be done?
Jun 27 '08 #1
6 2226
On May 21, 6:10 pm, Jason <paul...@excite .comwrote:
I would like to build a windows app or service that would read a .txt
file and than put the contents of that file in an email and send off
the email. WOuld that be very difficult?...ho w could this be done?
Hi,
Reading of text file can be done using WebClient's downloadstring
method if the file resides on remote host. If file is local, you can
use StreamReader.

You can send mail with attachments using System.Net.Smtp Client class.

A sample code would be:

' Instantiate SmtpClient Class
Dim emailClient As New SmtpClient("smt p.gmail.com")

' Instantiate MailMessage Class
Dim message As New MailMessage("fr om_here", "to_here", "subject_he re",
"body_here" )
message.Attachm ents.Add(New Attachment("att achment_path_he re")

' Credentials here <optional>
' Set credentials using System.Net.Netw orkCredential.. .
' .......

' Send mail
emailClient.Sen d(message)
Hope this helps,

Onur Güzel
Jun 27 '08 #2
OK...but I dont want to load the file as an attachment.

I want to read, for example \\server\docs\m yfile.txt
and than display the contents of file.txt in an email body

On May 21, 11:44*am, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
On May 21, 6:10 pm, Jason <paul...@excite .comwrote:
I would like to build a windows app or service that would read a .txt
file and than put the contents of that file in an email and send off
the email. *WOuld that be very difficult?...ho w could this be done?

Hi,
Reading of text file can be done using WebClient's downloadstring
method if the file resides on remote host. If file is local, you can
use StreamReader.

You can send mail with attachments using System.Net.Smtp Client class.

A sample code would be:

' Instantiate SmtpClient Class
Dim emailClient As New SmtpClient("smt p.gmail.com")

' Instantiate MailMessage Class
Dim message As New MailMessage("fr om_here", "to_here", "subject_he re",
"body_here" )
message.Attachm ents.Add(New Attachment("att achment_path_he re")

' Credentials here <optional>
' Set credentials using System.Net.Netw orkCredential.. .
' .......

' Send mail
emailClient.Sen d(message)

Hope this helps,

Onur Güzel
Jun 27 '08 #3
On May 21, 7:21*pm, Jason <paul...@excite .comwrote:
OK...but I dont want to load the file as an attachment.

I want to read, for example \\server\docs\m yfile.txt
and than display the contents of file.txt in an email body

On May 21, 11:44*am, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
On May 21, 6:10 pm, Jason <paul...@excite .comwrote:
I would like to build a windows app or service that would read a .txt
file and than put the contents of that file in an email and send off
the email. *WOuld that be very difficult?...ho w could this be done?
Hi,
Reading of text file can be done using WebClient's downloadstring
method if the file resides on remote host. If file is local, you can
use StreamReader.
You can send mail with attachments using System.Net.Smtp Client class.
A sample code would be:
' Instantiate SmtpClient Class
Dim emailClient As New SmtpClient("smt p.gmail.com")
' Instantiate MailMessage Class
Dim message As New MailMessage("fr om_here", "to_here", "subject_he re",
"body_here" )
message.Attachm ents.Add(New Attachment("att achment_path_he re")
' Credentials here <optional>
' Set credentials using System.Net.Netw orkCredential.. .
' .......
' Send mail
emailClient.Sen d(message)
Hope this helps,
Onur Güzel- Hide quoted text -

- Show quoted text -
Then you'll send the mail within your application, right?

So, place a richtextbox or textbox to download the content from remote
text file;

Dim myclient As New System.Net.WebC lient
textbox1.text = myclient.Downlo adString("\\ser ver\docs\myfile .txt")

Now you can set textbox1 as body of your outgoing mail in
MailMessage's constructors:
Dim message As New MailMessage("fr om", "to", "subject",
textbox1.text)

(see previous post for the rest)

Thanks,

Onur Güzel
Jun 27 '08 #4
On May 21, 11:10 am, Jason <paul...@excite .comwrote:
I would like to build a windows app or service that would read a .txt
file and than put the contents of that file in an email and send off
the email. WOuld that be very difficult?...ho w could this be done?
If the file is not at a remote location, it would be much easier to
just read the file with a FileStream. You should be able to find
plenty of examples on doing that from the msdn article on FileStream.

For sending it in an email, the place you want to go is

www.systemnetmail.com

It will walk you through the steps necessary for sending emails.

Thanks,

Seth Rowe [MVP]
Jun 27 '08 #5
in that case read the content from the txt file using StreamReader and
populate message body.

Also the name space is System.Net.Mail .SmtpClient
Mayur

"Jason" <pa*****@excite .comwrote in message
news:6f******** *************** ***********@k30 g2000hse.google groups.com...
OK...but I dont want to load the file as an attachment.

I want to read, for example \\server\docs\m yfile.txt
and than display the contents of file.txt in an email body

On May 21, 11:44 am, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
On May 21, 6:10 pm, Jason <paul...@excite .comwrote:
I would like to build a windows app or service that would read a .txt
file and than put the contents of that file in an email and send off
the email. WOuld that be very difficult?...ho w could this be done?

Hi,
Reading of text file can be done using WebClient's downloadstring
method if the file resides on remote host. If file is local, you can
use StreamReader.

You can send mail with attachments using System.Net.Smtp Client class.

A sample code would be:

' Instantiate SmtpClient Class
Dim emailClient As New SmtpClient("smt p.gmail.com")

' Instantiate MailMessage Class
Dim message As New MailMessage("fr om_here", "to_here", "subject_he re",
"body_here" )
message.Attachm ents.Add(New Attachment("att achment_path_he re")

' Credentials here <optional>
' Set credentials using System.Net.Netw orkCredential.. .
' .......

' Send mail
emailClient.Sen d(message)

Hope this helps,

Onur Güzel

Jun 27 '08 #6
On May 21, 8:03*pm, "Mayur H Chauhan" <ma...@orioninc .comwrote:
in that case read the content from the txt file using StreamReader and
populate message body.

Also the name space is System.Net.Mail .SmtpClient
Mayur

"Jason" <paul...@excite .comwrote in message

news:6f******** *************** ***********@k30 g2000hse.google groups.com...
OK...but I dont want to load the file as an attachment.

I want to read, for example \\server\docs\m yfile.txt
and than display the contents of file.txt in an email body

On May 21, 11:44 am, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
On May 21, 6:10 pm, Jason <paul...@excite .comwrote:
I would like to build a windows app or service that would read a .txt
file and than put the contents of that file in an email and send off
the email. WOuld that be very difficult?...ho w could this be done?
Hi,
Reading of text file can be done using WebClient's downloadstring
method if the file resides on remote host. If file is local, you can
use StreamReader.
You can send mail with attachments using System.Net.Smtp Client class.
A sample code would be:
' Instantiate SmtpClient Class
Dim emailClient As New SmtpClient("smt p.gmail.com")
' Instantiate MailMessage Class
Dim message As New MailMessage("fr om_here", "to_here", "subject_he re",
"body_here" )
message.Attachm ents.Add(New Attachment("att achment_path_he re")
' Credentials here <optional>
' Set credentials using System.Net.Netw orkCredential.. .
' .......
' Send mail
emailClient.Sen d(message)
Hope this helps,
Onur Güzel- Hide quoted text -

- Show quoted text -
Yes, my typo, correct one is System.Net.Mail .SmtpClient, thanks for
correcting.

Thanks,

Onur
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
7103
by: John | last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to able to load all 5000 pictures and view 50 per page using mysql_data_seek(). I would like to know what are the advantages and disadvantages of using a MySQL blob field rather than reading the images directly from the file? How does one insert an image into a blob field? Can it be done dynamically? Thank you John
3
7060
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt. Obviuosly, the file is fine on the server, so the attachment code I am using must be corrupting it, but I dont know what it is: // send email with attachment function emailAttachment($to, $subject, $message, $name, $email,
21
13155
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the server is on one line (\r\n at end) and is formed as - each of which is seperated by a space. Arguments with spaces in them are enclosed in quotations. So, I'm able to open a connection to the server. When I send a message to
8
1526
by: Dalibor | last post by:
I have following code for putting contenst of a file into a web page: <?php $filename = "../msd/news.txt"; $handle = fopen ($filename, "r"); $content = fread ($handle, filesize($filename)); fclose($handle); echo ($content); ?> But in file news.txt I have formating that is not showing, but interpreting.
9
3613
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so that its buffer is bigger than this. I did this expecting the data to be read in one pass.
0
1445
by: philip20060308 | last post by:
Hi all, Has anyone ever seen Python 2.4.1's httplib choke when reading chunked content? I'm using it via urrlib2, and I ran into a particular server that returns something that httplib doesn't expect. Specifically, in the code below where the error occurs, line == ''. Python 2.4.1 (#2, Oct 12 2005, 01:36:32) 20050518] on freebsd6 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2
2
3603
by: Sean | last post by:
I am trying to read a cookie I set but I am not sure if I really set it correctly or I am not reading it correctly. I was given the following instructions to set the cookie. It appears to be working because in Firefox browser I see the cookie listed for my domain I have been searching everywhere to find information on reading the cookie value that I set. I used the following code I found which returns 'no cookiez' in spite of the...
7
1862
by: atyndall | last post by:
Basically, I have a email script which (on the sending of the email) writes into a file handle called $fcf (on a new line) with the senders ip address ($ipaddress) and the time on which they sent their email ($time) in this format: $ipaddress--$time on a new line in $fcf. I am new to php and if someone could convert my normal language into PHP scripting I would be very grateful. if ($fcf contains $_SERVER with time() ) { Thanks
7
3347
by: bleachie | last post by:
Hey, I just need some help, my form seems to not send me all of the 'guestNames' and 'guestEmails' forms. i use this function to add more guestnames and guestemail fields based on the number of guests added. form.php function createGuestNameAndEmailElements() {
0
9990
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9835
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10473
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8028
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7177
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6068
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4689
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4285
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.