Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / May 2008

Tip: Looking for answers? Try searching our database.

reading and sending a file in email ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason - 21 May 2008 16:10 GMT
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?
kimiraikkonen - 21 May 2008 16:44 GMT
> 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
Jason - 21 May 2008 17:21 GMT
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

> > 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
[quoted text clipped - 27 lines]
>
> Onur Güzel
kimiraikkonen - 21 May 2008 17:34 GMT
> OK...but I dont want to load the file as an attachment.
>
[quoted text clipped - 34 lines]
>
> - 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
Mayur H Chauhan - 21 May 2008 18:03 GMT
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

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.com> wrote:
> On May 21, 6:10 pm, Jason <paul...@excite.com> wrote:
>
[quoted text clipped - 29 lines]
>
> Onur Güzel
kimiraikkonen - 21 May 2008 18:12 GMT
> in that case read the content from the txt file using StreamReader and
> populate message body.
[quoted text clipped - 44 lines]
>
> - Show quoted text -

Yes, my typo, correct one is System.Net.Mail.SmtpClient, thanks for
correcting.

Thanks,

Onur
rowe_newsgroups - 21 May 2008 17:55 GMT
> 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]

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.