Connect failed :IO::Socket::INET: connect: timeout is showing up in Perl . - perl

I have wriiten this script to send mail through gmail smtp to my gmail account . It is not working and giving the already mentioned error ?
use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
'smtp.gmail.com',
Hello => 'smtp.gmail.com',
Port => 587,
User => 'cetranger#gmail.com',
Password=> 'xxxxxx');
$mailer->mail('cetranger#gmail.com');
$mailer->to('cetranger#gmail.com');
$mailer->data;
$mailer->datasend("Sent from perl!");
$mailer->dataend;
$mailer->quit;

Try this:
use strict;
use warnings;
use Email::Simple;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP::TLS;
my $transport = Email::Sender::Transport::SMTP::TLS->new(
host => 'smtp.gmail.com',
port => 587,
username => 'cetranger#gmail.com',
password => 'xxxxxx'
);
my $message = Email::Simple->create(
header => [
From => 'cetranger#gmail.com',
To => 'cetranger#gmail.com',
Subject => 'Sent from perl!',
],
body => 'Sent from perl!',
);
sendmail( $message, {transport => $transport} );

This script should work in fact (I tested with my own gmail account successfully).
I suspect you have some firewall in-between that prevent you from connecting to gmail.
Could you try telnet smtp.gmail.com 587 from your host. You should have something like that:
host$ telnet smtp.gmail.com 587
Trying 173.194.67.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP da8sm6658151wib.6
If you do not have the last 3 lines, this means that you cannot connect directly to the gmail server. Then check as well your own firewall settings (if any).

Related

Perl mail attachment file size limit

I am using MIME::Lite module to send attachments in email and everything works fine until I realized attachment larger than 15mb cannot be sent successfully. Any suggestion on other module which not having size limit?
You should consider using a different module because that's what the author recommends (try Email::MIME, MIME::Entity or Email::Sender). However, it's not the module that determines the attachment size restriction.
The size limit you're seeing is set by your SMTP server. If you're not explicitly configuring your SMTP server you're using your local service which might differ depending on your OS. You're probably using sendmail or postfix.
See size limit in postfix
postconf | grep message_size_limit
See size limit in sendmail
grep MaxMessageSize /etc/mail/sendmail.cf
If you're using an external SMTP server they usually have their own size limits. Google has a 25MB size limit for their SMTP server smtp.gmail.com. If that's sufficient for you you could send your mail via Google by authenticating.
$msg->send(
'smtp', 'smtp.gmail.com',
Port => 465,
SSL => 1,
AuthUser => $user,
AuthPass => $password,
);
EDIT: I had some issues using MIME::Lite to work properly with Gmail SMTP server so I here's an example on how to use gmail.smtp.com with an alternative pacakge.
#!/usr/bin/env perl
use warnings;
use strict;
use Email::Sender::Simple qw( sendmail );
use Email::Sender::Transport::SMTP;
use Email::Simple;
my $user = 'username#gmail.com';
my $password = 'app-password';
my $host = 'smtp.gmail.com';
my $port = 465;
my $transport = Email::Sender::Transport::SMTP->new(
{
host => $host,
port => $port,
ssl => 1,
sasl_username => $user,
sasl_password => $password,
}
);
my $email = Email::Simple->create(
header => [
To => 'someone#example.com',
From => 'me#localhost',
Subject => 'Hello...',
],
body => "World!\n",
);
sendmail( $email, { transport => $transport } );

Perl smtp email send is not working

I'm trying to send emails from my gmail account, and get the error:
Error sending email: Connect failed :IO::Socket::INET: connect: timeout at /home/tas/perl5/lib/perl5/Email/Send/SMTP/TLS.pm line 45
I've tried several different email adresses (gmail and others) but the result is the same.
I use this code:
#!/usr/bin/perlml
use Email::Send;
print "Content-type: text/html\n\n";
my $mailer = Email::Send->new( {
mailer => 'SMTP::TLS',
mailer_args => [
Host => 'smtp.gmail.com',
Port => 587,
User => 'XXXX#gmail.com',
Password => 'XXXXXXXXX',
Hello => 'fayland.org',
]
} );
use Email::Simple::Creator; # or other Email::
my $email = Email::Simple->create(
header => [
From => 'XXXX#gmail.com',
To => 'XXXX#gmail.com',
Subject => 'test',
],
body => 'test',
);
eval { $mailer->send($email) };
die "Error sending email: $#" if $#;
What is wrong here? Any other ways to send emails using smtp?
Error sending email: Connect failed :IO::Socket::INET: connect: timeout at /home/tas/perl5/lib/perl5/Email/Send/SMTP/TLS.pm line 45
Looks like there is nothing wrong with your Perl code. It looks like this is a networking problem. Something in your network is preventing you from connecting to Gmail on port 587.
You probably need to discuss this with the system support people for your server.

CakePHP: send mail through SMTP to MS OUTLOOK -> SMTP Error: 504 5.7.4 Unrecognized authentication type

I figured that I'll try to find out if I can send mails via cmd line before writing a question here. So I followed these steps and sent an e-mail by cmd to myself and a collegue of mine who's working on the same app I am. The message from cmd line came in the format it should have come.
( internal app, should send mails only to my collegues' OUTLOOK accounts )
Everything seems to be connected fine so I figured I have an error in my cakePHP code:
Everything on mails code I have so far is this:
app/config/email.php
public $smtp = array(
'transport' => 'Smtp',
'from' => array('from#test.sk'),
'host' => 'ip_address_of_my_host',
'port' => 25,
'timeout' => 30,
'username' => 'from#test.com',
'password' => 'password',
'client' => null,
'log' => true,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
UsersController.php (test send mail function)
public function test_send_email() {
$this->autoRender = false;
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('smtp');
$email->from(array('from#test.com' => 'APP TEST'));
$email->to('me#test.com');
$email->subject('Subject of testing');
$email->send('Message of testing');
}
After 5 seconds of loading I get: SMTP Error: 504 5.7.4 Unrecognized authentication type
Solved:
I guess the authentication wasnt required on EXCHANGE, so I just removed the password parameter and works fine.
During research I found out this article, so the next step would be to contact EXCHANGE admins.
http://blogs.technet.com/b/exchange/archive/2006/12/28/3397620.aspx
I was getting the same error when using telnet on port 25. After changing to port 587, I was able to use authenticated SMTP.

sending email through exchange server via zend server

I want to send a local e-mail through exchange server
but zend give me this Message
"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."
this is my code
$mailTransport =
new Zend_Mail_Transport_Smtp('smtpserver.edu.com', array(
'auth' => 'login',
'username' => 'dummy.edu.com',
'password' => '123456',
'port' => '25',
));
Zend_Mail::setDefaultTransport($mailTransport);
$mail = new Zend_Mail();
$mail->setFrom('dummy.edu.com');//anas.azmeh#ucti.edu.my');
$mail->setBodyHtml('some message - it may be html formatted text');
$mail->addTo('dummy.edu.com', 'recipient');
$mail->setSubject('subject');
$mail->send();
I tried the same code in gmail configuration and it works perfectly
please help me as fast as possible
$mail = new Mail\Message();
$mail->setBody("Send Mail");
$mail->setFrom('test#gmail.com', 'Test Site');
$mail->addTo($email_id, 'Test Site');
$mail->setSubject('Your connection is not stablish');
$transport = new Mail\Transport\Sendmail();
$transport->send($mail);
I think that port 25, 23 and 587 are blocked
because I tried to telnet them but it give me fail, so the problem may come from these blocking

How to use Zend_Mail_Transport_Smtp with hosted Google Apps?

So I'm under the impression that bad things will happen if I don't use Zend_Mail_Transport_Smtp when sending lots of emails. Problem is...I can't figure out how to set it up. I am using Google Apps hosted email for my domain. So to access my email, I go to mail.mydomain.com, which takes me to a google login page.
This is the code that I am using, but it's not working.
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'webmaster#mydomain.com', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('mail.mydomain.com', $config);
Using "mail.mydomain.com" I get a "connection timed out" error (which makes me think its the wrong thing to use.
Using "smtp.mydomain.com" I get a "Could not open socket" error.
What am I doing wrong?
Since you are sending emails through gmail, you should use "smtp.gmail.com" and not your domain.
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'webmaster#mydomain.com', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Some more reference. Check the port using port scanner on remote end which are open, do a test if they reply packets, sometimes port 25 is not working so email fails, and also the SSL or TLS.
$config = array(
'ssl' => 'ssl', //TLS = tcp:// use port 25
//SSL = ssl:// use port 465 or 587
'port' => 465,
'auth' => 'login',
'username'=> 'x',
'password'=> 'b/c',
);
$tr = new Zend_Mail_Transport_Smtp('email-smtp.us-east-1.amazonaws.com', $config);
Zend_Mail::setDefaultTransport($tr);