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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:36:50+00:00 2026-05-31T18:36:50+00:00

I have a scenario where I am to send email using our own SMTP

  • 0

I have a scenario where I am to send email using our own SMTP server using Java. I have an application deployed on Tomcat 6.

  1. The functionality to send email works when we use GMail SMTP.
  2. The functionality does not work when I try using our own servers.

I get the following error

MailException occured while sending emailMail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: 172.16.16.1, port: 25;
  nested exception is:
    java.net.ConnectException: Connection timed out. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: 172.16.16.1, port: 25;
  nested exception is:
    java.net.ConnectException: Connection timed out

The problem is that everything works fine using the same credentials and configuration parameters from a Perl Script.

I am on a Debain system.

I doubt there is some kind of access rights issue. I am new to Linux and have very limited knowledge.

Can anybody please help?

The Perl SCRIPT

Pasting the Perl script below for reference

#!/usr/bin/env perl

# System Modules
use strict;
use warnings;
use Mail::Sender;

my $subject = q/Testing Mail Server./;
my $smtp = q/localhost/;
my $from = 'Test <no-reply@xxxx.com>';
my $to   = 'shardul@xxxx.com';
my $msg = q/Hi Testing.../;
my $auth    = q{};
my $authid  = q{};
my $authpwd = q{};

eval {
    sendmail( $smtp, $from, $to, q{}, $subject, $msg, $auth, $authid, $authpwd );
};
if ( $@ ) {
    print STDERR "Confirmation Mail Sending to $to Failed.\n";
    print STDERR 'ERROR: ' . $@;
}

sub sendmail {
    my ( $smtp, $from, $to, $bcc, $subject, $msg, $auth, $authid, $authpwd ) = @_;
    my $sender = new Mail::Sender { smtp => $smtp, from => $from };
    $sender->Body( 0, 0, 'text/html' );
    my $result = $sender->MailMsg(
        {
            replyto   => 'test@xxxxxx.com',
            to        => $to,
            bcc       => $bcc,
            subject   => $subject,
            msg       => $msg,
            auth      => $auth,
            authid    => $from,
            authpwd   => $authpwd,
        }
    );
    if ( $result < 0 ) {
        die "$Mail::Sender::Error\n";
    }
}
  • 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-05-31T18:36:51+00:00Added an answer on May 31, 2026 at 6:36 pm

    You’re getting a java.net.ConnectException so the Java VM can’t connect to the mail server. It’s not really a mail problem since Java can’t see the mail server.

    You say:

    everything works fine using the same credentials and configuration parameters from a Perl Script.

    Is the Perl script running on the same system as Java? If not it looks like network connectivity problem between the Java host and Mail server.

    If the Perl script is running on the same system double check the script is doing what you think it is, perhaps using something like the netstat command. If the server has multiple network interfaces check the Java VM isn’t bound to one that can’t contact the mail server.

    Update – Your Perl script is not using your mail server at 172.16.16.1 to send mail. You can see from this line:

    my $smtp = q/localhost/;
    

    that the script is sending mail via the mail server running on the same host as the script.

    It does look like a network problem. Try running the following command:

    telnet 172.16.16.1 25
    

    If you have network connectivity to the mail server on port 25 you’ll see something like:

    $ telnet smtp.gmail.com 25
    Trying 173.194.67.109...
    Connected to gmail-smtp-msa.l.google.com.
    Escape character is '^]'.
    220 mx.google.com ESMTP fw5sm12835658wib.0
    

    If you don’t have network connectivity you’ll see something like this:

    $ telnet 172.16.16.1 25
    Trying 172.16.16.1...
    telnet: connect to address 172.16.16.1: Operation timed out
    telnet: Unable to connect to remote host
    

    If you do have connectivity then there must be something on the local system preventing the JVM from connecting, possibly an iptables rules. For example, network connectivity might be restricted by user id. Are you running the Perl script as the same user as Tomcat?

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

Sidebar

Related Questions

I have PEAR Mail and Mail_mime all working very nicely using gmail's SMTP server
I have the following scenario: Users send email messages to the special mail addresses
I have the following scenario. I send a XML file to a server as
i have a scenario where in i need to send an xml as a
I have to add e-mail notifications to a client server application. Notifications happen as
I have the following code: public static void Send(this MailMessage email) { if (!isInitialized)
Scenario: I have a number of Codeigniter applications that I am improving the email
I'm working on an android application project, and I have a scenario where I
I have a scenario where I need to send a series of data across
I have a web application that needs to fire off a long-running SQL Server

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.