aspose file tools*
The moose likes Java in General and the fly likes Help building an infinite mail sender Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help building an infinite mail sender" Watch "Help building an infinite mail sender" New topic
Author

Help building an infinite mail sender

Erick Travis
Greenhorn

Joined: Jul 22, 2014
Posts: 5
Hello, guys. New to the ranch, looks amazing . I need some help building a mail sender that never stops sending mails to the correct recipients (this is determined by a field in a SQL table). I got another program that schedules meetings and defines the participants, these participants are saved in a PARTICIPANT table in my database. The mail sender checks the PARTICIPANT table and sends mails to the participants that have 0 in the INV_SENT field, it gets data for the mail from the MEETING table (data like meeting place, date and things like that), sends the mail (using the data it drew from MEETING) and afterwards changes the INV_SENT field to 1. I got a mail sender class and the JDBC connection made. The things that I got doubts in is in making constantly check the PARTICIPANT table looking for recipients that have INV_SENT set to 0, sending the mail drawing the data from the MEETING table and then changing the field to 1. Can you, please, give me some advice and/or suggestions as in how to do this? Any help is appreciated and I don't know if this belongs to Java in General or Beginning Java. Thanks in advance and also. how do I get that little cow that some guys have beneath their name?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11411
    
  16

Welcome.

I'm not sure about the answer to your programming issue, but I do know this:
cows

Also this


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Erick Travis
Greenhorn

Joined: Jul 22, 2014
Posts: 5
Thanks, man. Got a craving for some cows now :F
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
Advice on technical writing such as your original post.

Paragraphs are your friends for organizing your thoughts.

Numbered lists or "bullet points" are also helpful.

When I see a big block of run-on text, my eyes glaze over (MEGO) and I think "this person has not organized his thoughts on the problem so why should I even try to figure out what he is trying to say."

Bill
Erick Travis
Greenhorn

Joined: Jul 22, 2014
Posts: 5
Hello, guys. New to the ranch, looks amazing .

I need some help building a mail sender that never stops sending mails to the correct recipients (this is determined by a field in a SQL table).

I got another program that schedules meetings and defines the participants, these participants are saved in a PARTICIPANT table in my database.

The mail sender:
1.- Checks the PARTICIPANT table and sends mails to the participants that have 0 in the INV_SENT field.
2.- It gets data for the mail from the MEETING table (data like meeting place, date and things like that).
3.- Sends the mail (using the data it drew from MEETING) and afterwards changes the INV_SENT field to 1.

I got a mail sender class and the JDBC connection made.

The things that I got doubts in is in making it constantly check the PARTICIPANT table looking for recipients that have INV_SENT set to 0,
sending the mail drawing the data from the MEETING table and then changing the field to 1.

Can you, please, give me some advice and/or suggestions as in how to do this?
Any help is appreciated and I don't know if this belongs to Java in General or Beginning Java.

Thanks in advance and also, how do I get that little cow that some guys have beneath their name?

Thank you, Bill, for the advice. You are right and I hope it's clearer now.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11411
    
  16

There are many ways this could be done...it sort of depends on what you mean by "never stops". For example, if your PARTICIPANT table is updated only hourly, you really don't need to check it every microsecond.

but a few thoughts...

1) There are java scheduling classes/APIs. I've never used them, so I can't give you more specific info, but I believe you would write them to say "fire off a job every X seconds to do something". As long as your JRE is running, the tasks should fire.

2) Write this program to run exactly once, doing everything you need. Then use cron or windows task schedule or whatever to fire off the job every minute, or 5 minutes, or whatever

3) If updating the scheduler program is an option, you could have it send a message to your emailer program that says "Hey - I just changed the PARTICIPANT table so go take a look". The email program could sit by doing nothing until it gets a message.


I don't think you want a job that constantly queries your PARTICIPANT table, since that could really impact your application or database performance. Don't waste time doing stuff if you don't need to.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
Well, for one thing, "constantly checks" is not what you want, it would burn CPU time an DB access for no purpose. Surely checking every few minutes or maybe even longer would be sufficient.

Java has the TimerTask class in the java.util package - however it has been a while since I did anything like this and there may be a better tool somewhere.

Bill
Erick Travis
Greenhorn

Joined: Jul 22, 2014
Posts: 5
Heeeeeello, guys. Sorry for taking so long, I went out on a little holiday trip.
I finished the mail sender and it was a success.
I mixed a lot of SQL queries inside a method and set a TimerTask to execute it every 15 min.
Thank you all for everything. You rock, guys.
 
wood burning stoves
 
subject: Help building an infinite mail sender