sending email through exchange server via zend server - zend-framework

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

Related

php 5.6 mail and SSL

I found myself unable to send mails since I upgraded to php5.6.
$to = "Test1 <*******#gmail.com>";
$body = "Hi,\n\n this is just test email";
$headers = array(
'From' => '*******#gmail.com',
'To' => $to,
'Subject' => 'test email'
);
$smtp = Mail::factory('smtp', array(
'host' => 'smtp.sendgrid.com',
'port' => '587',
'auth' => 'login',
'username' => '*****',
'password' => '*****',
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo $mail->getMessage();
} else {
echo "<p> Message successfully sent!</p>";
}
login authentication failure [SMTP: STARTTLS failed (code: 220, response: Begin TLS negotiation now)]
If I use my Gmail account with this code, i get an error too
$smtp = Mail::factory('smtp',array (
'host' => 'ssl://smtp.googlemail.com',
'port' => '465',
'auth' => 'login',
'username' => '******#gmail.com',
'password' => '*******'
));
authentication failure [SMTP: Invalid response code received from server (code: 534, response: 5.7.14 Please log in via your web browser and 5.7.14 then try again. 5.7.14 Learn more at 5.7.14 https://support.google.com/mail/answer/78754 jz4sm22875767wjb.16 - gsmtp)]
I have an oid application running with ZF1, and I found that there was a problem on this call Zend_Mail_Protocol_Smtp :
stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)
I've read that some changes had been made in php 5.6 concerning OpenSSL, but I don't know what changes I need to do.
I had the same trouble and stumbled upon the solution, and these are clearly related to changes in PHP 5.6 (which I'm not all together happy about).
The verify_peer and verify_peer_name are now by default set to true - requiring an extra level of security between the two machines involved in a streamed port. I don't want this when I'm dealing with SMTP, the STARTTLS encryption is enough for me. So turn these off I added some code to the Net/SMTP.php file
$options = array('ssl' => array('verify_peer_name' => false, 'verify_peer' => false));
$result = $this->_socket->connect($this->host, $this->port, $persistent, $timeout, $options);
The socket timeout default specified in php.ini is not being used by this function. So I changed the default in 'smtp.php' to:
$timeout = 60; // previously null;
Hope that helps somebody else. Cheers Murray
I know that this question is kinda old but I will leave the answer here, maybe someone else will find it useful: https://stackoverflow.com/a/34090707/5639805

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.

Using Zend Mail with SMTP Authentication gives an error

I'm trying to create a form that sends an email using SMTP authentication, but I keep receiving an error. I've read a bunch of posts online and this is the code I've come up with so far. Does anyone see anything wrong with the code below? Any help would be greatly appreciated.
Thanks
Bob
$configSMTP = array(
'port' => 587,
'auth' => 'login',
'username' => '***',
'password' => '***'
);
$transport = new Zend_Mail_Transport_Smtp('mail.server.com', $configSMTP);
$mail = new Zend_Mail();
$mail->setReplyTo($config['replyto']);
$mail->setBodyText($message);
$mail->setFrom($params[$config['emailID']], $params[$config['nameID']]);
$mail->addTo($config['sendto']);
$mail->setSubject($config['subject']);
try {
$mail->send($transport);
} catch(Exception $ex) {
Mage::getSingleton('core/session')->addError('There was an error submitting your request.');
}
Mandril's SMTP uses TLS.
http://help.mandrill.com/entries/21738477-What-SMTP-ports-can-I-use-
Enable it in your config array.
$configSMTP = array(
'ssl' => 'tls',
'port' => 587,
'auth' => 'login',
'username' => '***',
'password' => '***'
);
Would direct you maybe to section on resource plugins form Zend Mail. Give a better list of the options and shows how to assign them through your app.ini file.
That said, assuming your arguments are valid that looks fine.
What exception are you catching? You must be getting an error message. Can you telnet from this machine to your mail server? Want to eliminate network/auth issues.
It's hard to say without knowing what exception you're getting.
There might be several reasons, can you connect to the SMTP-server.. Is the port 587 really open? Do you have a firewall, and if so, might it be blocking the connection to that port? Are you really sure those credentials are valid? Have you tried manually connecting to the SMTP-server?
If not, see how you can do it with Telnet: How to test an SMTP server using Telnet
You could also try using a transactional email service. That way you wouldn't need to manage an SMTP-server or even think about deliverability, etc. You would just outsource it to someone else.
There are various providers, some of them are:
AlphaMail
Mandrill
PostageApp
If you're using AlphaMail, you could just use the AlphaMail PHP-client and send your emails like the example below:
include_once("comfirm.alphamail.client/emailservice.class.php");
$email_service = AlphaMailEmailService::create()
->setServiceUrl("http://api.amail.io/v1")
->setApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");
$person = new stdClass();
$person->userId = "1234";
$person->firstName = "John";
$person->lastName = "Doe";
$person->dateOfBirth = 1975;
$response = $email_service->queue(EmailMessagePayload::create()
->setProjectId(12345) // You AlphaMail project (determines template, options, etc)
->setSender(new EmailContact("Sender Company Name", "from#example.com"))
->setReceiver(new EmailContact("Joe Doe", "to#example.org"))
->setBodyObject($person) // Any serializable object
);
The templates are constructed in the AlphaMail Dashboard using the Comlang templating language. This means that you can easily edit your emails at any time, without having to dig through code. Templates in Comlang look something like:
<html>
<body>
<b>Name:</b> <# payload.firstName " " payload.lastName #><br>
<b>Date of Birth:</b> <# payload.dateOfBirth #><br>
<# if (payload.userId != null) { #>
Sign Up Free!
<# } else { #>
Sign In
<# } #>
</body>
</html>

CakePHP SMTP EMail Not Working on Server

I am able to send SMTP Emails from my local server machine in CakePHP while I am not able to do the same on my GoDaddy live server, in CakePHP.
Any ideas for the same?
Thanks
Answer is below as per my experience with GoDaddy:
Below code is working for me over GoDaddy server using CakePHP SMTP Email:
Email.php file inside config folder - CakePHP 2.4 MVC version:
// for Live Server GoDaddy.com domain
public $smtp = array(
'transport' => 'Smtp',
'host' => 'ssl://smtpout.asia.secureserver.net', // important
'port' => 465, // important
#'timeout' => 30,
'username' => 'no-reply#godaddy-domain.com',
'password' => 'password',
#'tls' => false,
#'log' => false,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
And here is the controller file code below:
// Controller Code to Send Actual Email
// email configuration
$Email = new CakeEmail('smtp');
$Email->from(array('no-reply#godaddy-domain.com' => 'App Name'))
->sender('no-reply#godaddy-domain.com', 'App Name')
->to(array($email))
->bcc(array('xyz#xyz.com'))
->subject('Test Email from GoDaddy')
->emailFormat('both')
->send($hash.'<br><strong>My</strong> message 45 قبل الميلاد، مما يجعله أكثر من');
Hope it helps !
Thanks
Update your code to check for an error message:
if(!$this->Email->send()) {
CakeLog::write('debug', $this->Email->smtpError);
}
Then check the /app/tmp/logs/debug file on the server.

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);