Solved

coding to automatically email a line of text

Posted on 2011-02-18
6
197 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now