Solved

coding to automatically email a line of text

Posted on 2011-02-18
6
213 Views
Last Modified: 2012-05-11
Ok I'm struggling a little bit on how to approach this. We are trying to get an email to go out every morning at a certain time with a random phrase that we specify. Here's the catch, the phrases come from an ebook, we use the kindle software and when you make notes on particular phrases you can export them to things like text files, etc. What we are looking to do is write a script or batch file or something that will look into this file pick a random line (phrase) that we had exported from our ebook and email it to the specified email address. Do you have any suggestions on what I should do to achieve this? what you would do? any programs or scripts to use or if I have to write a script should it be a batch or what? or would web based be the way to go?

Suggestions or advice would be highly appreciated.

Thanks!
0
Comment
Question by:dirtbikedude
6 Comments
 
LVL 10

Expert Comment

by:John Claes
ID: 34924603
So

You have already exported it to a TextFile.

Than I would suggest a Small app that you can schedule or a windowsService that has a Timer to run Once a day.

What must be done. :

Read the File to know the number of lines.
c  : http://www.mrx.net/c/readfunctions.html
c#: http://blogger.xs4all.nl/zomerf/archive/2008/10/02/416167.aspx
Use this as a max for your random generating number
Read that line of the file

Create the MailMessage and add the line to the body

Send the mail
c :  http://bytes.com/topic/c/answers/843485-how-send-email-c
c#: http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/a75533eb-131b-4ff3-a3b2-b6df87c25cc8

Why a batch : Easy to use, easy to run, easy to schedule, easy to deploy :
Why a WindowsService : scheduling is automated, easy to deploy , invisible running.


regards
poor_beggar
0
 
LVL 3

Expert Comment

by:QuinnDester
ID: 34924625
If you are already using a database, storing the lines of text in the database and scheduling it from the database would make controlling the aspects of the email much more dynamic and versatile
0
 

Author Comment

by:dirtbikedude
ID: 34935690
If I wanted to do it as a batch file. Can you guys give me the code that I would make a batch out of so that it takes a line of text from a text file and emails it?
0
 
LVL 10

Accepted Solution

by:
John Claes earned 500 total points
ID: 34941063
dirtbikedude:

I'm not going to write the program for you :

but here some lines
reading file :
http://blogger.xs4all.nl/zomerf/archive/2008/10/02/416167.aspx
Randomize :
http://www.c-sharpcorner.com/UploadFile/mahesh/RandomNumber11232005010428AM/RandomNumber.aspx
sending mail :
http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/a75533eb-131b-4ff3-a3b2-b6df87c25cc8

 
private void SendLineByMail(string FIlePath)
{
      int randomLineNumber = GetRandomLineNumber(FIlePath);
      string fileLine = 
     
}




private int GetRandomLineNumber(string FIlePath)
{
	List<string> lines = GetLineNumbers(FIlePath);
	int randomLine= random.Next(lines.Count);
	SentLineByMail(lines[randomLine], randomLine);
}


private List<string> GetLineNumbers(string FIlePath)
{
            try
            {
                List<string> lines = new List<string>();
		// Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(FIlePath))
                {
                    String line;
                    // Read and display lines from the file until the end of 
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        lines.add(line);
                                                
                    }
                }
		return lines ;
            }
            catch (Exception e)
            {
                return 0;
            }

}

private void GetLineNumbers(string line, int lineNumber)
{
	System.Web.Mail.SmtpMail.SmtpServer="SMTP Host Address";
	System.Web.Mail.SmtpMail.Send("Fromtest@abc.com","Totest@abc.com","The Random Line Of today is ["+lineNumber+"]",line);
}

Open in new window

0
 
LVL 53

Expert Comment

by:Dhaest
ID: 35321628
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question