You can view the tutorials best in Google Chrome, Mozilla Firefox, Opera, higher version of Internet Explorer

Send Java EMail in Specific Time Interval Automatically & Dynamically

Core Java » On Oct 7, 2012 By Sivateja

Let us see how to send automatic and dynamic email using Java, this application will send email in fixed interval of time, even if you want you can change this application to send email every day at particular time :-), to wish your friends/family.

Directory Structure

GMailServer.java

DBScheduler.java

ReadPropertiesFile.java

Testing.java

Constants.java

java4s_Props.properties

Explanation

  • Run DBScheduler.java to start this application
  • First time email will sent after 2 seconds and repeats every 10 seconds until you stop your application
  • Just change .properties file and change what ever you want, you no need to touch any .java files :-)
  • You no need to touch GMailServer.java

Jars Required

  • mail.jar
  • activation.jar
  • commons-email-1.0.jar

Download these jars…..

 

Output








By ( Java/J2EE Developer & Web Designer )
Founder of Java4s.com. You can contact me at sivateja [at] java4s.com


Comments

7 Responses to “Send Java EMail in Specific Time Interval Automatically & Dynamically”
  1. hi frnd,this is really awesome tutorial for java developers ,actuallly when iam trying to execute this example im getting error follws….

    Email Sent Succesfully…
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
    class javax.mail.MessagingException: Unknown SMTP host: smtp.gmail.com;
    nested exception is:
    java.net.UnknownHostException: smtp.gmail.com
    at javax.mail.Transport.send0(Transport.java:218)
    at javax.mail.Transport.send(Transport.java:80)
    at JAVAEmail.GMailServer.sendMail(GMailServer.java:61)
    at JAVAEmail.Testing.run(Testing.java:15)
    at java.util.TimerThread.mainLoop(Unknown Source)
    at java.util.TimerThread.run(Unknown Source)

    error….plz help in execution by sending an email to my mail id ,
    thanks in advance

  2. ram says:

    Hi frnd
    I also practiced wit this code its really helpful ,Thanks

  3. neha says:

    sir from where i can download BarCode128Java4s.java file….please give me the respective link..

  4. Jinshad says:

    Gud job….. Thanks a lot….

  5. Hareesh says:

    I am getting the following error plse help to slove this

    Scheduler Starterd…

    Exception in thread “Timer-0″ java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
    at javax.mail.Session.loadProvidersFromStream(Session.java:928)
    at javax.mail.Session.access$000(Session.java:174)
    at javax.mail.Session$1.load(Session.java:870)
    at javax.mail.Session.loadResource(Session.java:1084)
    at javax.mail.Session.loadProviders(Session.java:889)
    at javax.mail.Session.(Session.java:210)
    at javax.mail.Session.getDefaultInstance(Session.java:299)
    at emial.GMailServer.(GMailServer.java:41)
    at emial.Testing.run(Testing.java:12)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)

  6. developer says:

    Is it recommended to use “Timer” in Java EE web applications?

  7. Saleen Conzalo says:

    I am getting the following error plse help to slove this

    Scheduler Starterd…
    javax.mail.AuthenticationFailedException: 534-5.7.14 Please log in via your web browser and then try again.
    534-5.7.14 Learn more at
    534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 mi8sm21900010pdb.91 – gsmtp

    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:648)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:583)
    at javax.mail.Service.connect(Service.java:313)
    at javax.mail.Service.connect(Service.java:172)
    at javax.mail.Service.connect(Service.java:121)
    at javax.mail.Transport.send0(Transport.java:190)
    at javax.mail.Transport.send(Transport.java:120)
    at java4s.GMailServer.sendMail(GMailServer.java:60)
    at java4s.Testing.run(Testing.java:15)
    at java.util.TimerThread.mainLoop(Unknown Source)
    at java.util.TimerThread.run(Unknown Source)
    Email Sent Succesfully…

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
So, What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs

Most Recent Tutorials
Hibernate Recent Posts
Spring Recent Posts
Struts Recent Posts
Recomandded Links
Current & UpComing Tutorials
Sitemap :
spring Hibernate struts Json Ajax Log4j Log4j coreJava Servlets Web Services


Upcoming
  Web Services [ SOAP ], JSP
Facebook_Java4s  Twitter_Java4s  GooglePlus_Java4s  Youtube_Java4s 
© 2010 - 2014 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.