473,387 Members | 1,542 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,387 software developers and data experts.

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?...how could this be done?
Jun 27 '08 #1
6 2200
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?...how 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.SmtpClient class.

A sample code would be:

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

' Instantiate MailMessage Class
Dim message As New MailMessage("from_here", "to_here", "subject_here",
"body_here")
message.Attachments.Add(New Attachment("attachment_path_here")

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

' Send mail
emailClient.Send(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\myfile.txt
and than display the contents of file.txt in an email body

On May 21, 11:44*am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
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?...how 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.SmtpClient class.

A sample code would be:

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

' Instantiate MailMessage Class
Dim message As New MailMessage("from_here", "to_here", "subject_here",
"body_here")
message.Attachments.Add(New Attachment("attachment_path_here")

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

' Send mail
emailClient.Send(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\myfile.txt
and than display the contents of file.txt in an email body

On May 21, 11:44*am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
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?...how 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.SmtpClient class.
A sample code would be:
' Instantiate SmtpClient Class
Dim emailClient As New SmtpClient("smtp.gmail.com")
' Instantiate MailMessage Class
Dim message As New MailMessage("from_here", "to_here", "subject_here",
"body_here")
message.Attachments.Add(New Attachment("attachment_path_here")
' Credentials here <optional>
' Set credentials using System.Net.NetworkCredential...
' .......
' Send mail
emailClient.Send(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.WebClient
textbox1.text = myclient.DownloadString("\\server\docs\myfile.txt" )

Now you can set textbox1 as body of your outgoing mail in
MailMessage's constructors:
Dim message As New MailMessage("from", "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?...how 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**********************************@k30g2000 hse.googlegroups.com...
OK...but I dont want to load the file as an attachment.

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

On May 21, 11:44 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
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?...how 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.SmtpClient class.

A sample code would be:

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

' Instantiate MailMessage Class
Dim message As New MailMessage("from_here", "to_here", "subject_here",
"body_here")
message.Attachments.Add(New Attachment("attachment_path_here")

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

' Send mail
emailClient.Send(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**********************************@k30g2000 hse.googlegroups.com...
OK...but I dont want to load the file as an attachment.

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

On May 21, 11:44 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
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?...how 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.SmtpClient class.
A sample code would be:
' Instantiate SmtpClient Class
Dim emailClient As New SmtpClient("smtp.gmail.com")
' Instantiate MailMessage Class
Dim message As New MailMessage("from_here", "to_here", "subject_here",
"body_here")
message.Attachments.Add(New Attachment("attachment_path_here")
' Credentials here <optional>
' Set credentials using System.Net.NetworkCredential...
' .......
' Send mail
emailClient.Send(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
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...
3
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....
21
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...
8
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));...
9
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...
0
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...
2
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...
7
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...
7
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.