Zend_Mail Could not open socket - zend-framework

i'm using Zend_Mail to send out an email from Aruba PEC.
$config = array('auth'=>'login',
'ssl' => 'ssl',
'port' => 465,
'username'=>'user#pec.it',
'password'=>'pass');
$tr = new Zend_Mail_Transport_Smtp('62.149.152.91',$config);
Zend_Mail::setDefaultTransport($tr);
$mail = new Zend_Mail();
$mail->setBodyHtml('Mail test');
$mail->setFrom('user#pec.it');
$mail->addTo('marco#email.it');
$mail->setSubject('Test');
$mail->send();
but i receive this error: " Could not open socket ".
Now if i try to exceute this script on my local pc it works correctly, but wen i try to exceute it on server in my local area network i receive this error.
than i i try with another ip address (no certifaction account) it works correctly.
(so i think that is a problem of configuration server??)
thanks

You need to have OpenSSL installed on the PC. Is your server Windows? It is a bit of a pain if you are.

Related

Sending email from specific server gives socket forbidden error

I get this error
An attempt was made to access a socket in a way forbidden by its access permissions xxx.xxx.xxx.xxx:587 when sending email from a godaddy server.
I have seen many questions like this but what's unique here is that, this code works on my local computer. It also works on my other Go daddy hosting Server.
This original server has TLS 1.0, because i needed TLS 1.2, I purchased a deluxe hosting plan and moved my code to this new server, then i start getting this error. I've searched everywhere and used every combination of port 587, 465, 25 along with ssl = false or true.
Any ideas please?
using (SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587))
{
MailMessage mail = new MailMessage();
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("********#gmail.com", "********");
smtpClient.EnableSsl = true;
string fromEmail = "********#gmail.com";
mail.From = new MailAddress(fromEmail, "System");
mail.To.Add(new MailAddress(toEmail));
mail.Body = body.ToString();
mail.Subject = subject;
smtpClient.Send(mail);
}
Sounds like a firewall or AV or other port blocking software preventing outbound connections to port 587. Check your server config and look in the windows event log as there might be an entry in there indicating who did the blocking.
Try to use port 2525 for 587, 465, 25. Some cloud providers disable all outbound traffic from 587, 465, 25 ports.
It seems like Godaddy is blocking emails from its servers when you use an outside smtp like smtp.gmail.com. At least that seems like the case with this Plesk Hosting Account. The other Economy Hosting works well with Gmail smtp.
Also, the emails will only send from Godaddy server, running the code locally on Visual studio gave an error.
I changed my code to this:
using (SmtpClient smtpClient = new SmtpClient("relay-hosting.secureserver.net", 25))
{
MailMessage mail = new MailMessage();
smtpClient.Credentials = new NetworkCredential("yourdomain#yourdomain.com", "****");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
string fromEmail = "yourdomain#yourdomain.com";
mail.From = new MailAddress(fromEmail, "Name");
mail.To.Add(new MailAddress(toEmail));
mail.Body = body.ToString();
mail.Subject = subject;
smtpClient.Send(mail);
}

Mail Exception only on server

Stage
I have a web application which I deployed recently. Application needs to send emails for several reasons.
I am using yandex business email service for my domain, have many email accounts for my domain, and I can use those email addresses without any problem.
I have written some code to send email on my Laravel application, using Laravel's Mail::send. See it below at #2. And you can see my config/mail.php settings at #1 below.
I am testing my application on my windows computer, with WAMP server.
My production server is VPS server running Linux. PHP version 5.5.29.
Problem
Everything works perfectly on my local test environment;
I can send mails, and they are delivered to hotmail, gmail or my domain's emails without any problem.
On the server however, I receive an error when I try to send an email. See #3 for error.
On the same server, I am able to send emails using PHPMailer with same email accounts, email settings and credentials, and without any problem.
Question and thoughts
Everything works on my local environment as expected and that makes me think it is a problem with my server configurations, PHP version, configuration or extensions, but I do not have the knowledge to judge that.
What have I tried and did not worked
Commented these lines to send email from default mail address.
And also changed my default email address with another one, which is also working everywhere except on production server of this project;
//$transport = Mail::getSwiftMailer()->getTransport();
//$transport->setUsername($username);
//$transport->setPassword($password);
Disabled mail encryption. Set;
'encryption' => '',
Tried different driver;
'driver' => 'mail',
1) My config/mail.php
'driver' => 'smtp',
'host' => 'smtp.yandex.com',
'port' => 587,
'from' => ['address' => 'name#domain.com', 'name' => 'name'],
'encryption' => 'tls',
'username' => 'name#domain.com',
'password' => 'password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
2) Code I use
Mail::send($message, $data, function ($message) use ($account, $to, $subject)
{
$acc = config("mail.accounts.$account");
$senderAddress = array_get($acc, 'address');
$username = array_get($acc, 'username', $senderAddress);
$password = array_get($acc, 'password', '');
$senderName = array_get($acc, 'name', $acc['address'], $senderAddress);
$replyToAddress = array_get($acc, 'replyTo.0', $senderAddress);
$replyToName = array_get($acc, 'replyTo.1', $senderName);
$message->from($senderAddress, $senderName)
->replyTo($replyToAddress, $replyToName)
->subject($subject)
->to($to);
$transport = Mail::getSwiftMailer()->getTransport();
$transport->setUsername($username);
$transport->setPassword($password);
});
Explanation for code above:
This code basically allows me to send emails to any email account,
and from many email accounts I have. And like I said, this works perfectly on my local test environment.
3) The Error
Swift_TransportException in AuthHandler.php line 181:
Failed to authenticate on SMTP server with username
"name#domain.com" using 2 possible authenticators
4) Working PHPMailer Script
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.yandex.com";
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Username = $sender; // SMTP account username
$mail->Password = $password; // SMTP account password
$mail->SetFrom($sender, 'Name');
$mail->AddReplyTo($sender, 'Name');
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->AddAddress($to, $to);
$mail->Send();
It's hard to say what the problem can be. Or why it works on your development environment. But a quick google search gave me the following settings for smpt.yandex.com:
mail server address — smtp.yandex.com;
connection security — SSL;
port — 465.
So, it shouldn't work on your dev environment. Why it does work is a mystery to me.
see: https://yandex.com/support/mail/mail-clients.xml

Cake Email Times Out During Send

I'm trying to use CakeEmail in a web application, but I keep running into a timeout error. All my Googling and Stacking only give me the idea that something is not configured correctly, but I can't seem to find what config option I'm missing or filling incorrectly. I'm trying to send using my Gmail account.
Gmail Config:
public $gmail = array(
'host' => 'ssl://66.249.93.111',
'port' => 465,
'timeout' => 30,
'username' => 'my_gmail_account_name',
'password' => 'my_gmail_account_password',
'transport' => 'Smtp'
);
in app/Config/email.php
Email code:
$Email = new CakeEmail('gmail');
$Email->from(array('my_gmail_account_name' => 'Dev'));
$Email->to('my_gmail_account_name');
$Email->subject('Export Email Test');
$Email->send('This is a test email for ExportJobs.');
(As an additional note, the code that runs here is as part of a Cake Console program, so these methods are called when I run Console/cake file_name from the command line; also, that IP is the Gmail SMTP IP. When I try using the name, I get some DNS issue).
Does anyone happen to see what I'm missing?
Thanks for your time!
I found the problem I was having; it's a pretty silly error.
I completely forgot that to use the gmail domain for SMTP, I have to preface the domain name as "smtp.gmail.com". Once I did that it used SMTP and worked just fine.

how to send mail using perl with attachement?

I've try to send mail using perl with attachment I've tried with Email::Stuff and MIME::Lite,during run time i got some error as Authentication failed or server not connected can anybody help me?
corresponding code is:
use MIME::Lite;
use Net::SMTP;
### Adjust sender, recipient and your SMTP mailhost
my $from_address = 'atme04#gmail.com';
my $to_address = 'thiyagu040#gmail.com';
my $mail_host = 'smtp.gmail.com';
### Adjust subject and body message
my $subject = 'A message with 2 parts ...';
my $message_body = "Here's the attachment file(s) you wanted";
my $your_file_zip = 'my.zip';
$msg = MIME::Lite->new (
From => $from_address,
To => $to_address,
Subject => $subject,
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";
MIME::Lite->send('smtp', 'smtp.gmail.com' ,
Port =>465 ,
Timeout=>320 ,
Debug => 1 ,
Hello => $mail_host,
User => $from_address,
Password => 'Thiyagu.04' );
#$mime_msg->send() or die "Error sending message: $!\n";
#MIME::Lite->send('smtp',$mail_host,AuthUser=> $from_address, AuthPass=>"apssword");
$msg->send();
error message is;
SMTP Failed to connect to mail server: A connection attempt failed because the connected party did not properly respond aft
er a period of time, or established connection failed because connected host has failed to respond.
at mail.pl line 54.
thanks in advance
The error message seems pretty clear to me. The problem is with your connection to the mail server - so changing the module that you're using is unlikely to achieve anything useful. I don't know enough about Gmail's server settings to comment on what the problem is, but this page has some suggestions that you might follow. Specifically, you could check that the Gmail account has 'allow authentication' turned on and that your mail client (the Perl program) is using SSL for the connection.
Also, this might be easier if you used an email that was specifically designed for use with Gmail. Email::Send::SMTP::Gmail looks tailor-made for your requirements.

I do i setup sendmail in php.ini on wampserver 2.1 to post form data on local machine ?

I have created some forms using zendframework on my local machine that send the form content via email.
I would like to test the functionality locally and have read some posts regarding configuring the php.ini file to do this but not sure which is the correct method ?
can anyone help me with this, many thanks
On Windows you will have to use SMTP to send the message. There is a drop in fake sendmail for Windows but it still requires an SMTP server.
You could use your ISP's sendmail server if they offer one, or you can set one up on the local machine. 1, 2, 3, 4
Since you are using Zend Framework, you can alternatively use Zend_Mail to send through an SMTP server (Zend_Mail can also use sendmail, but since it isn't configured, you can't use that transport). In that case see Sending via SMTP, SMTP Authentication, and Securing SMTP Transport.
Here is some sample code for sending an SMTP message with AUTH and TLS security.
<?php
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
$config = array('ssl' => 'tls',
'port' => '465', // 25 if no ssl
'auth' => 'login',
'username' => 'user',
'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('smtp.example.com', $config);
$mail = new Zend_Mail();
$mail->addTo('user#domain')
->setSubject('Mail Test')
->setBodyText("Hello,\nThis is a Zend Mail message...\n")
->setFrom('sender#domain');
try {
$mail->send($transport);
echo "Message sent!<br />\n";
} catch (Exception $ex) {
echo "Failed to send mail! " . $ex->getMessage() . "<br />\n";
}
Also note, your ISP may not require you to auth at all if you are sending from one of their IP addresses, but you probably do have to authenticate with your username and password, in which case you will want to use TLS.