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 9101267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:05:08+00:00 2026-06-17T01:05:08+00:00

am using liferay 6 and created one custom class..i want to create mail notification

  • 0

am using liferay 6 and created one custom class..i want to create mail notification function…I have written following code in my class

private void SendEmail(NotificationObject pNotificatonObj,
            String[] pReciepientAddresses) throws MessagingException {

        log.info("In SendMail");
        Properties props = new Properties();
        props.put("mail.debug", "true");
        props.put("mail.smtp.socketFactory.fallback", "false");
        Session session = Session.getInstance(props);
        Message msg = new MimeMessage(session);
        InternetAddress addressFrom = new InternetAddress(
                pNotificatonObj.get_From());
        msg.setFrom(addressFrom);
        // InternetAddress addressTo = new
        // InternetAddress(pNotificatonObj.get_To());

        InternetAddress[] addressTo = new InternetAddress[pReciepientAddresses.length];
        log.info("ADDRESS ARRAY LENGTH In Send Mail: - " + pReciepientAddresses.length);
        for (int i = 0; i < pReciepientAddresses.length; i++) {
            log.info("ADDRESS ARRAY LENGTH In Send Mail: - " + pReciepientAddresses[i]);
            addressTo[i] = new InternetAddress(pReciepientAddresses[i]);
        }
        // log.info("INTERNET ADRESS ARRAY LENGTH : - " + addressTo1.length);
        msg.setRecipients(RecipientType.TO, addressTo);

        // msg.addRecipients(Message.RecipientType.TO, addressTo);
        // Setting the Subject and Content Type
        msg.setSubject(pNotificatonObj.get_Subject());
        msg.setContent(pNotificatonObj.get_HtmlString().toString().toString(),
                "text/html");
        Transport.send(msg);
        log.info("Send Mail Leave");
    }

I have written following things in my root.xml file of tomcatserver directory

<Resource
                     name="mail/MailSession"
                     auth="Container"
                     type="javax.mail.Session"
                     mail.imap.host="localhost"
                     mail.pop.host="localhost"
                     mail.store.protocol="imap"
                     mail.transport.protocol="smtp"
                     mail.smtp.host="smtp.gmail.com"
                     mail.smtp.port="465"
                     mail.smtp.auth="true"
                     mail.smtp.starttls.enable="true"
                     mail.smtp.user="My@gmail.com" //MyEmailId
                     password="*******" //My password
                     mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
   />

But its giving me following error …can anyone please help me out..where am doing mistake

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
  nested exception is:
    java.net.ConnectException: Connection refused: connect
  • 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-17T01:05:09+00:00Added an answer on June 17, 2026 at 1:05 am

    None of those properties you’re setting in your root.xml file are being used by your application.

    You need to change your application to either look up the JavaMail Session using JNDI instead of creating it yourself using Session.netInstance, or you need to change your application to set all those properties on the Properties object that you use to create the new Session object.

    Don’t forget to read the JavaMail FAQ for common mistakes and how to connect to Gmail. (Hint: you don’t need any of the socketFactory properties.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started using Netbeans with following stack Liferay, icefaces with jBoss. Is
I am using liferay and i have created my own portlet which have just
I have created a simple portlet using the Liferay MVC framework and have added
I am new to velocity. I want to create new Liferay theme using bootstrap.
I have checked on Using custom services or liferay services in liferay themes (velocity
I've created a new theme using the Liferay Eclipse IDE and have modified build.xml
I am using liferay workflow. I want to create my own workflow definition. Now
I am using Liferay 6.1, Tomcat and MySQL. I have a custom-sql sentence for
I am using Liferay 6 . I have read that Liferay Hooks can be
I just started to use Liferay and I want to develop a portlet using

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.