Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8239943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:19:10+00:00 2026-06-07T20:19:10+00:00

How to write a mail application with java mail API that run all time

  • 0

How to write a mail application with java mail API that run all time at glassfish server and search a specific time in the database and send mail at that time. i have web application written in JSF that need to send mail at specific time given in database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:19:11+00:00Added an answer on June 7, 2026 at 8:19 pm

    For gmail, use below code

    import org.apache.commons.mail.*;
    
    public class GmailEmailWorking {
    
        public static void main(String[] args) {
            String myEmailId = "xyz@gmail.com";
            String myPassword = "password";
            String senderId = "xyz@yahoo.com";
            try {
                MultiPartEmail email = new MultiPartEmail();
                email.setSmtpPort(587);
                email.setAuthenticator(new DefaultAuthenticator(myEmailId, myPassword));
                email.setDebug(true);
                email.setHostName("smtp.gmail.com");
                email.setFrom(myEmailId);
                email.setSubject("Hi");
                email.setMsg("This is a test mail ... :-)\n\nPlease check attachements that I have sent.\n\nThanks,\nFahim");
                email.addTo(senderId);
                email.setTLS(true);
    
                EmailAttachment attachment = new EmailAttachment();
                attachment.setPath("/Users/fahadparkar/Desktop/Fahim/tables.xlsx");
                attachment.setDisposition(EmailAttachment.ATTACHMENT);
                attachment.setDescription("Excel");
                attachment.setName("tables.xlsx");
                email.attach(attachment);
    
                email.send();
                System.out.println("Mail sent!");
            } catch (Exception e) {
                System.out.println("Exception :: " + e);
            }
        }
    }
    

    Below are list of jar files you will need

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

    To send from other server, you will need to do changes at below line

    email.setSmtpPort(587);
    email.setHostName("smtp.gmail.com");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my application i am using to send mail with attachments i write the
We currently have an Java application that can be deployed on clients or run
How can I write an iOS application that displays mail from my GMail account?
my question is, I have to send mail at specific time daily, is there
I'm trying to write application that periodically receives e-mails. It writes every mail into
I have to write a ASP.NET application in C# that returns the mailquota of
I'm in the process of testing an application that takes mail out of a
I am going to send a mail from my application and I have added
I'm using Zend_Mail in a Zend Framework application to send an e-mail with the
We write applications that send out automated email alerts using SMTP. We generally configure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.