469,282 Members | 2,119 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

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 1990
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by John | last post: by
3 posts views Thread by Paul Lamonby | last post: by
21 posts views Thread by JoKur | last post: by
8 posts views Thread by Dalibor | last post: by
reply views Thread by philip20060308 | last post: by
2 posts views Thread by Sean | last post: by
7 posts views Thread by bleachie | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.