Cannot connect to mailserver using javamail - jakarta-mail

I am trying to connect to IMAP server to read mails knowing that the IMAP mailserver is a local APache JAMES Mailserver. When using pop3 protocol, everything succeed, sending / retrieving messages between clients... But when i changed the protocol to imap, connection exceptiion is being thrown i dunno why...
This is My code :
#Stateless
public class Mailer{
#Resouces(name = "mail/javamailsession")
private Session session;
public void connect(){
IMAPStore store = (IMAPStore)session.getStore("imap");
store.connect("localhost","test#mydomain.org","myPass");
...
...
The exception is being thrown from here at :
store.connect(...
Exception is :
java.mail.MessagingException : Connection refused : connect;
nested exception is :
java.net.ConnectionException: Connection refused : connect
Knowing that the result of telnet process is :
Me : telnet localhost imap
Cmd : Ok James IMAP4rev1 server server pc_name is ready
Me : 01 login test#localhost 123456
Cmd : 01 Ok login completed
This means in a way or another that the imap is enabled in the server... So why should such exception occur :S Anybody has an idea ?

Most likely you have a firewall or anti-virus product that's allowing the connection from telnet but preventing the connection from your application. It looks like your application is a Java EE application. I assume the Java EE server is running on the same machine that the mail server is on, and that you ran telnet from.

Related

Failed to connect to cc-clickhouse.ads.aliyuncs.com port 8443: Operation timed out

When I'm trying to connect my ClickHouse instance on Alibaba Cloud with https protocol from my Mac, and this is the response error:
Failed to connect to cc-xxxx.germany.ads.aliyuncs.com port 8443: Operation timed out
enter image description here
curl --cacert ./Downloads/ClickHouse-CA-Chain.pem https://cc-clickhouseinstance.connection.string.ads.aliyuncs.com:8443/ping
I have tried ping, and it shows ok, so what the problem would be?
How to connect ApsaraDB for ClickHouse instance on Alibaba Cloud using https?
Maybe you should check your instance security group, be sure the public IP of your PC is on the allow list.
If you don't know how to get your public IP, check below.
https://ip.taobao.com/ipSearch
Or you can switch to connect from ECS instances and put public IP or intranet IP on the list. Just like this👇
Data Security Rules Configuration Example
[Reference]
https://www.alibabacloud.com/help/doc-detail/393349.htm

RDS SQL Server - error when trying to use Database Email

I am trying to configure Database Email on RDS for SQL Server.
I used this guide https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.DBMail.html
I am using existing, working SES credentials (used currently in EC2 instance)
The outbound security group rule is 0.0.0.0/0
When trying to send a email I get the below error:
The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 6 (2021-02-25T20:57:01). Exception Message: Could not connect to mail server. (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond [aws ip]:587).
)
Any other ideas on this one?
The solution was to set up a VPC Endpoint
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-set-up-vpc-endpoints.html#send-email-set-up-vpc-endpoints-procedure

Service Broker behind NAT and port forwarding results in "corrupted message has been received" error

Sending message via SQL Server Service Broker from one machine to another.
Sender - Windows Server 2012 R2 with SQL Server 2014 12.0.4213.0 Standard over NAT that has port forwarding for Service Broker from public IP:port to local SQL Server IP:port. Let's say, for example, the port is 26223 and it forwards to SQL Server 4022.
Receiver - CentOS 7 with SQL Server 2017 RC2 Express as web server with the same specific port opened for Service Broker. (updating to latest SQL Server CU - 14.0.3030.27 did not help)
I sent message from Sender to Receiver and firstly got error in sys.transmission_queue about wrong alghoritm, then I found out that I have encryption key alghoritms different on sender's and receiver's endpoints and changed receiver endpoint key encryption alghoritm to match sender's.
After that, the message I sent appeared in sys.transmission_queue with another error - Service Broker/Database Mirroring network protocol error occurred. In SQL Profiler I found more details:
Broker:Corrupted Message - A corrupted message has been received. The binary message preamble is malformed.
On the Receiver side SQL Profiler shows that:
Audit Broker Login: 4 - Negotiate Failure - An error occurred while receiving data: '996(Overlapped I/O event is not in a signaled state.)'.
Audit Broker Login: 5 - Authentication Failure
Sometimes I also got that error at Receiver side in addition to previous:
Audit Broker Login: 4 - Negotiate Failure - An error occurred while receiving data: '24(The program issued a command but the command length is incorrect.)'.
I have only one message for that instance waiting in sys.transmission_queue on Sender side.
UPDATE:
I used ssbdiagnose utility and here is what it says:
D 29835 MainServer MainDatabase Messages on conversation handle 13c07ab1-6b8d-e711-80c5-002590cb2a25 (conversation id 3a7d0dd0-c957-4fe8-a98e-1cb56713023c) from service sbSenderService to service sbReceiverService cannot be transmitted dues to the following problem: Service Broker/Database Mirroring network protocol error occurred.
An internal exception occurred: No such host is known
D 29933 WebServer WebDatabase The routing address TCP://[NAT ip address was here]:26223 for service sbSenderService does not match any of the IP addresses for MainServer
An internal exception occurred: Value cannot be null.
Parameter name: value
An internal exception occurred: No such host is known
P 29945 Cannot parse the routing address: unknown
So, the new error came into play: The routing address TCP://[NAT ip address was here]:26223 for service sbSenderService does not match any of the IP addresses for MainServer
As I understand it, my MainServer (Sender) does not know the NAT IP Address that is in TCP headers and marks that TCP package malformed, right? How to fix it?
UPDATE2: we set VPN tunnel between servers and the same errors still exists. The test CentOS server had all ports opened and no Selinux. For now I assume that Service Broker does not work between CentOS and Windows.
UPDATE3: updating to latest SQL Server CU on CentOS - 14.0.3030.27 did not help

SQL Azure VM (Resource Manager) can't send DBMail (Port 587 blocked)

I created a new VM for SQL Server and trying to setup the dbmail. The smtp server settings are all valid but I can't send emails out. I keep on getting following error:
The mail could not be sent to the recipients because of the mail server failure.
(Sending Mail using Account 1 (2016-07-20T09:19:34).
Exception Message: Could not connect to mail server. (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 159.122.224.196:587).
)
I tried doing a telnet check on the IP and port no. from my my local machine and SQL Server VM. While the local machine just works fine, the SQL Server VM can't connect to the port.
I also tried to open a port 587 using the link http://michaelsync.net/2015/09/28/where-is-the-endpoint-setting-for-vm-in-new-azure-portal but even after allowing a port 587, I still can't send emails. Any help will be much appreciated.
NOTE: The IP address 159.122.224.196 belongs to sendgrid.
What E-mail (SMTP) server are you using?
Make sure that you're configuring connectivity to it correctly and that the E-mail server is

Transport.send(message) throws Network is unreachable while trying to send the mail from my java application

i have been working on this application that sends email from my local RHEL server.
the mail path is:
1. local server to exchange server (outlook, office365)
2. exchange server to mail related domain.
when i test my application from my local PC-WindowsXP it works fine (it sends the mail).
but when i try the same from my RHEL server it throws:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 25; timeout -1;
nested exception is:
java.net.SocketException: Network is unreachable
and telnet from the server works fine.(i.e telnet exchange-server-name 25)
my properties are :
'Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", mailServer );
props.put("mail.smtp.port", "25");
props.put("mail.smtp.starttls.enable", "true");'
PS:
1. i tried updating the mail.jar, started TLS(using starttls),
2. tried enabling ssl(i.e props.put("mail.smtp.ssl.enable", "true");) while using port 465.
3. tried setting the smtp type to TLS using port 587.
all suggestions will be appreciated.
See the JavaMail connection debugging tips, but it looks like you have a basic networking problem preventing access from your server to the mail server, perhaps because of a firewall.

Resources