Connect to localhost failed using Mail::Sendmail module on Windows 10 - windows

I have the following code:
#!C:\Perl\bin\perl.exe -w
use strict;
use warnings;
use Mail::Sendmail;
sendmail(
From => 'xxxxxx#hotmail.com',
To => 'xxxxxx#hotmail.com',
Subject => 'test email',
Message => "body of the message",
);
I get the following error:
Connect to localhost failed (An attempt was made to access a socket in a way forbidden by its access permissions.) no (more) retries!
I'm not sure how to correct it, any idea? I'm using Windows 10.

Your local system isn't offering an SMTP service
You need to specify an SMTP server by specifying the host name in the smtp parameter of your call to sendmail

Related

OpenSSL::SSL::SSLError while testing the net/smtp library

I am trying to send emails using the net/smtp library but I receive the following error message:
SSL_connect returned=1 errno=0 state=unknown state: unknown protocol (OpenSSL::SSL::SSLError)
The code I am using is an extract from Peter Cooper's Beginning Ruby book, modified to use SSL, as required by yahoo servers:
require 'net/smtp'
message = %q{
From: Private Person <me#privacy.net>
To: myself <username#yahoo.com>
Subject: SMTP e-mail test
This is a test e-mail message.
}
smtp = Net::SMTP.new('smtp.mail.yahoo.com', 587)
smtp.enable_ssl
smtp.start('example.org', 'username#yahoo.com', 'password', :login) do |s|
s.send_message message, 'me#privacy.net', 'username#yahoo.com'
end
I tested the above code with Ruby 2.3.1 and Ruby 2.5.1 but I keep receiving the same error message.
By using Net::SMTP#enable_ssl (which is an alias to Net::SMTP#enable_tls), you are instructing the Ruby SMTP client to open a TLS tunnel as the very first step after connecting to the server. This requires the server to also support this on the used server port.
With Yahoos SMTP servers, they support this mode on port 465. With many other providers, you will see that they only support opportunistic TLS on port 587.
What happens there is that the client first starts with plain text SMTP and then negotiates with the server whether they support to update the connection to a TLS tunnel by using the STARTTLS command.
With net/smtp in Ruby, you can use Net::SMTP#enable_starttls instead.
If you are not sure of the server supports STARTTLS and you want to gracefully fallbvack to plaintext transfer of your password and the email to the server, you can also use Net::SMTP#enable_starttls_auto.
Thus, with Yahoo, you have two options:
you can use Net::SMTP#enable_tls on port 465
or you can use Net::SMTP#enable_starttls on port 587

Cannot connect HTTPS target via HttpSocket using an HTTP proxy

When connecting an external https url, the http proxy server would return the following error:
stream_socket_client(): SSL operation failed with code 1. OpenSSL
Error messages: error:140770FC:SSL
routines:SSL23_GET_SERVER_HELLO:unknown protocol
stream_socket_client(): Failed to enable crypto
stream_socket_client(): unable to connect to ssl://xxx.xxx.xxx:8080
(Unknown error)
It seems cakephp HttpSocket uses the url's scheme to connect the proxy. Can we separate the scheme between proxy and the real destination?
more from the code:
$http_socket = new HttpSocket();
$http_socket->configProxy(array(
'host' => 'xxx.xxx.xxx',
'port' => '8080'
));
$results = $http_socket->post(
'https://yyy.yyy.yyy'
);

Net::SFTP::Foreign new failed with transport

When I use transport API of Net::SFTP::Foreign to connect to remote server on windows, It reports error
"Invalid option 'host' or bad combination of options" after
Net::SFTP::Foreign->new is invoked
code is below:
pipe $pR,$pW;
$sftp = Net::SFTP::Foreign->new("$user\#$ip",transport=>[$pR,$pW]) or
$rdyTCE{$city1} = 1;
According to module documentation available on CPAN: http://search.cpan.org/~salva/Net-SFTP-Foreign-1.81/lib/Net/SFTP/Foreign.pm#API
transport => [$in_fh, $out_fh, $pid]
allows one to use an already open pipe or socket as the transport for the SFTP protocol.
So you don't need host. Pipes will be used.

connect server over net::ssh

hy
i write this code in my script
def connect_sql
Net::SSH.start( #host, #user, :port=>22, :verbose => :debug ) do |ssh|
puts ssh.exec!("./root/scripts/MysqlCleanInstance.sh #{#uid}")
end
end
The probleme is for etablish a conenction between two server we use dns .The DNS information are in /etc/resolv.conf.
i dont know why when i try to connect to another server i get this error:
, [2014-01-08T17:55:34.905977 #28115] DEBUG -- tcpsocket[3f87c7e6b534]: received packet nr 5 type 51 len 44
D, [2014-01-08T17:55:34.906129 #28115] DEBUG -- net.ssh.authentication.session[3f87c7e5b2b0]: allowed methods: publickey,password
D, [2014-01-08T17:55:34.906309 #28115] DEBUG -- net.ssh.authentication.methods.keyboard_interactive[3f87c7e58948]: keyboard-interactive failed
E, [2014-01-08T17:55:34.906487 #28115] ERROR -- net.ssh.authentication.session[3f87c7e5b2b0]: all authorization methods failed (tried none, publickey, hostbased, password, keyboard-interactive)
/var/lib/gems/1.8/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in `start': Net::SSH::AuthenticationFailed (Net::SSH::AuthenticationFailed)
from clean_instance.rb:87:in `connect_sql'
Make sure your SSH keys are in place. It appears you are not able to authenticate over SSH, even after all authentication methods have been tried.
The reason you are unable to connect to another server is likely because you are not able to authenticate with that other server using a SSH key, which I assume you were able to do with the first server.

APNS Connection Issue

OK, I know there has been a lot of discussion regarding APNS connection failures. Most of the discussion recommends checking the outgoing server port 2195 to be sure it will allow the connection. This is not my problem, although I am experiencing the 'connection refused' error (111).
I have validated communication between my server and the sandbox server be receiving a 200 response from the Apple Gateway. I know my certificates are good because I have tested the connection using openssl from a Mac. I have also been able to connect with the gateway once from my server but cannot get a consistent connection.
The test code I am using is as follows:
$ctx = stream_context_create();
stream_context_set_option($ctx,'ssl', 'local_cert', $pem);
stream_context_set_option($ctx, 'ssl', 'passphrase', $key);
$gateway = 'gateway.sandbox.push.apple.com';
$port = '2195';
$remote_socket = 'ssl://'.$gateway.':'.$port;
$fp = stream_socket_client($remote_socket, $err, $errstr, 60,STREAM_CLIENT_CONNECT, $ctx);
if (!$fp){
echo $err.'<br>';
echo $errstr.'</br>';
echo 'error=apple failed to connect';
} else {
fclose($fp);
echo 'success';
}
I have placed the .pem file in the same directory as the script file, removed the use of the passphrase, specified verify_peer, used the STREAM_CLIENT_ASYNC_CONNECT and the STREAM_CLIENT_PERSISTENT flags without success.
Is this an issue with something that I am doing, an issue with the apns sandbox server or is this what I should expect from the apns? Any insights or help you can provide is greatly appreciated -- my hair is getting pretty thin!
Regards.
PS -- If I remove the passphrase I get a 115 error saying the key cannot be accessed.
Despite being able to connect at least once, it turns out that you cannot get access to the APNS gateway without, at least, a virtual dedicated server on GoDaddy. At a minimum of $80 per month, paid upfront, that is too expensive. On to other means.
Some other things to try :
Use STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT in the stream_socket_client call
Don't use verify_peer
Check that the owner of the PHP script has enough rights to read the pem file and connect to a port located elsewhere (ie/ not just localhost)

Resources