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

  • Home
  • SEARCH
  • 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 6588391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:02:32+00:00 2026-05-25T17:02:32+00:00

This problem is driving me nuts. I have the following code: <html> <body> <%@

  • 0

This problem is driving me nuts. I have the following code:

<html>
<body>
<%@ page import="java.util.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<%
String host = "exchsrv2";
String to = "alan@domain.com";
String from = "apeince@domain.com";
String subject = "test";
String messageText = "body test";

Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", "25");
Session mailSession = Session.getDefaultInstance(props, null);

Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);

Transport.send(msg);
out.println("Mail was sent to " + to);
out.println(" from " + from);
out.println(" using host " + host + ".");
%>
</body>
</html>

Okay, the problem is, I get the following error:

javax.servlet.ServletException: javax.mail.MessagingException: Could not connect to SMTP host: exchsrv2, port: 25;
nested exception is:
java.net.SocketException: Permission denied: connect
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.alan_jsp._jspService(alan_jsp.java:113)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

I know Exchange server is there. I can telnet to it just fine. My Exchange server is setup to not require authentication. I got a program that works fine in C#/.NET, and it works fine, so I know the problem isn’t in the Exchange server. What am I doing wrong here?

  • 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-25T17:02:32+00:00Added an answer on May 25, 2026 at 5:02 pm

    Well offhand I would say there is an authentication issue when trying to connect. You are not providing any username or password, unless your exchange server doesn’t require username and password.


    UPDATE: If using JDK 7 see the following post, it resolved this issue:

    Defect – JDK7 Permission Denied with Sockets when using VPN

    “More digging around and it seems the VPN client has IPv6 disabled which is causing issues with JDK7. If I use the following flag -Djava.net.preferIPv4Stack=true I no longer see the errors. Is this workaround expected or is this an issue?”


    public class MailTest {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws MessagingException {
            String host = "smtp.gmail.com";
            String to = "myEmail@gmail.com";
            String from = "myEmail@gmail.com";
            String subject = "test";
            String messageText = "body test";
    
            Properties props = System.getProperties();
            props.put("mail.host", host);
            props.put("mail.transport.protocol", "smtp");
            props.put("mail.smtp.port", "25");
    
            // If using authentication, otherwise comment out
            props.put("mail.smtp.auth", "true");
    
            // Gmail requires TLS, your server may not
            props.put("mail.smtp.starttls.enable", "true");
    
            Session mailSession = Session.getDefaultInstance(props, null);
    
            Message msg = new MimeMessage(mailSession);
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject(subject);
            msg.setSentDate(new Date());
            msg.setText(messageText);
    
            Transport transport = mailSession.getTransport("smtp");
    
            //connect with authentication
            //transport.connect(host,"myUsername" , "myPassword");
    
            //connect without authentication
            transport.connect();
            transport.sendMessage(msg, address);
    
            transport.close();
    
            System.out.println("Mail was sent to " + to);
            System.out.println(" from " + from);
            System.out.println(" using host " + host + ".");
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NHibernate is driving me 'Nuts'!!! I have the following mapping. Which returns this error
I've been having this problem for a while and it's driving me nuts. I'm
This has been driving me nuts all day. I have a weird bug that
This thing is driving me nuts. I have a UserControl that is called WebUserControl.
This has been driving me nuts for a week now. I have a class
This has been driving me nuts all day. I've seen this problem crop up
This is driving me nuts. I have a working text based application. It has
I have a simple yet hard problem here that is driving me nuts ...
I'm sure this is simple but it's driving me nuts. I have a ListBox
This one is driving me nuts. The problem occurs in a two-server-system, where 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.