[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

coding to automatically email a line of text

Posted on 2011-02-18
6
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Simple Linear Regression

649 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