I'm trying to send an email using the Swift_SmtpTransport but I'm getting the following error:
501 5.5.2 <[::1]>: Helo command rejected: invalid ip address
The SMTP server is a remote server and it works from my production server, but not from my development machine, which is running OS X.
It also doesn't bother to throw an exception, instead it required me to use a logger plugin to find out why it wasn't working.
What can I do to make it use a real IP address?
I did some poking around in the code and found it.
When configuring the SMTP transport, you need to call setLocalDomain(). Using PHP on OS X, this defaults to "::1", which is rejected by the remote server. I've just added a line in my development configuration to set that:
$transport = Swift_SmtpTransport::newInstance('mail.pantsburger.com', 587);
if (SITE_ENV == SITE_ENV_DEV) {
$transport->setLocalDomain('[127.0.0.1]');
}
I think this is also a bug with Swiftmailer - it really should be throwing an exception for something like this, rather than just listing each recipient as "failed".
Related
Hi guis I have been migrating an application to new server, is an Ubuntu server but on the new server I have some problem to send emails using Cakephp 2.0.
If the host on cake mail config is localhost I have the following error:
SMTP Error: 530 5.7.0 Must issue a STARTTLS command first
Search on the internet the solutions may be is config SMTP ssl://mydomain.com.br on php.ini or using ssl host like this ssl://mydomain.com.br on cake mail config. On the first option nothing change, error persist and with host ssl on cake mail config I have the following error:
Unable to connect to SMTP server.
I make a simples test using only php mail() function and the email is been sent.
On this server I config postfix and dovecot may be this can be the problem?
you can use 'PHPMailer'.
it's simple and easy.
https://github.com/PHPMailer/PHPMailer
I'm using Swiftmailer to send mail through a contact form with Symfony. My ISP allows me to send mail from a remote server with my mail account information (username, password and smtp).
My problem is that when I'm sending a mail from my development site (from my desktop server) I can do it and the mail is sent, but in the production environment Swiftmailer raise an exception saying that the client host is rejected (code 554 5.7.1) and failed to send the mail. I have tried to debug this with the app/console swiftmailer:email:send and I get the same error :
Exception occurred while flushing email queue:
Expected response code 220 but got code "554",
with message "554 5.7.1 <unknown[here-example-ipv6]:49545>:
Client host rejected: Access denied " [] []
The ipv6 (here-example-ipv6) is corresponding to a dns of my host that I have not configured, but I don't understand why Swiftmailer believes that this ip is corresponding to the client host, my configuration seems (app/config/config.yml and parameters.yml) to be good because that's work fine from my desktop. Any help would be appreciated, thank.
Ok, I get it. I was confused with the error message because I thought it was comming from Switmailler, but it was comming from my ISP mail server.
The problem was that when you want to send a mail from a remote location my ISP require to activate SSL encryption.
So I have added two more parameters for the Swfitmailler configuration :
port: 465
encryption: ssl
and now that's fine. But because I was testing from a production environment, the cache has to be cleared in order the changes to take effect.
I recently transferred my server to VPS & now email function doesn't work for external emails.
Following are the settings I'm using:
$transport = Swift_SmtpTransport::newInstance('ns1.example.com', 465, 'ssl')
->setUsername('testing#example.com')
->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
And the error that I'm getting is this:
SMTP error from remote mail server after initial connection:
host dedrelay.where.example.net [XX.XXX.XXX.XX]: 554
m1plded02-01.prod.mesa1.example.net : DED :
gWqF1p02c0cB4sG01 : DED : ESMTP
No Relay Access Allowed From XXX.XXX.XXX
I've tried telnet & response is ok. I've tried following:
telnet ns1.example.com 465
Response was:
connected to xx.xxx.xxx.xx
I'm also not able to configure my desktop email client. Can anyone tell a solution? Any help will be appreciated.
EDIT
I'm not even able to send an email through server's webmail. Same error.
You tried telnet ns1.example.com 465 and it connected. This shows the SMTP server is up and running and your computer can reach it. But this is not all you need.
The error message No Relay Access Allowed From 123.123.123.123 means the SMTP server is configured to not accept emails from this IP address for relay, i.e. emails that needs to be passed to another server for delivery.
This is an anti-abuse measure and it means the SMTP server is configured correctly.
There is nothing wrong with your SwiftMailer configuration. Any email client (including the desktop client, as you said) you use, the answer is the same.
You need to contact the system administrator of the SMTP server and ask them to allow your IP address to use their SMTP server as relay. If they are your ISP it's also possible that the server allows relay only after authentication: you have an username/password pair (that you use to read the emails, f.e.) and you need to use it in order to send emails through their SMTP server. But this is only a supposition (this is how it usually works); you have to ask them to know for sure.
On my localhost (Linux Mint OS) Swiftmailer is working fine with the following code, but whenever I move it up to my server is just hangs at the send function and then gives me an internal server error.
I currently have my email setup through Google Apps, so maybe SMTP will not work for this situation? If thats the case, how do you suggest I change this from SMTP.
Also, whenever I send an email like this, it is showing up with a from address of the one in the username area. I want it to show up with the from address in the "setFrom" function.
//Include the swiftmailer class
require_once 'comm/swiftmailer/swift_required.php';
//Create a message
//Pass it as a parameter when you create the message
$message = Swift_Message::newInstance();
$message->setSubject('My Subject');
$message->setFrom(array('noreply#domain.com' => 'No Reply'));
$message->setTo(array('me#domain.com' => 'Me'));
$message->setBody($emailContent, 'text/html');
//Create transport class and email the message
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('useracctname')->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
Thanks a lot for any help!
This might be a port problem on the server. Port 465 could be closed to prevent spamming. It could also be that the server's version of PHP lacks SSL support.
I am wondering though, could it be that I am not using the local mail server so it wont allow SMTP?
If you address gmail as explicitly as you do, it's very unlikely you're using another transport type or a different server.
Also, what about using one of the other transport types?
I think SMTP is your only option to get it running with Gmail. It could, however, be that your server is providing a mail() based service (obviously with a different sender address than GMail though). In that case, you may be able to use Swiftmailer's mail transport.
I had the same problem : I was able to send gmail email in local (after updating that configuration : https://www.google.com/settings/security/lesssecureapps ) but not in production.
To fix my problem I've logged to my gmail account with my production ip / from my production server and answer the gmail security question.
One of the solution to log to your gmail account with your production ip, is to
open an ssh tunnel (ssh -2NfCT -D 5000 yoursshuser#yourdomain.org)
configure you browser to use that proxy (eg Firefox :to Preferences > Advanced > Network > Settings > Manual proxy configuration > SOCKS Hosts: localhost / Post: 5000 / SOCKS v5 )
log to you gmail account as usual
The error outputed by Symfony was :
app.ERROR: Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "joe.doe" using 1 possible authenticators [] []
well, here is the solution.
if you are sending SMTP mail you should create email account at the server then use this email info at your code.
the server will not send the email if you don't have valid email account to send using it
when you use "from".
this should be a true correct email account a fake one.
the only possible reason to send using fake account is using mail() function.
I'm developing a zend framework application that includes a simple email function. The development version is running on my computer, which is running Ubuntu. The production version is going to run on a production server.
When trying to send a test email to myself, I get an exception with the message: "Unable to send mail". I don't know if this is an environment issue, or a code issue. I'm not using a transport so I think it is defaulting to Zend_Mail_Transport_Sendmail. Here's my code:
public function sendtestAction()
{
$mail = new Zend_Mail();
$mail->setFrom('test#aol.com', 'Test Email');
$mail->addTo('my#email.com', 'My Name');
$mail->setSubject('This is just a test.');
$mail->setBodyText('This is only a test.');
$mail->send();
}
Update: I tried a different approach by setting the SMTP transport to use localhost:
transport = new Zend_Mail_Transport_Smtp('localhost');
Zend_Mail::setDefaultTransport($transport);
I got a different error this time: "Connection refused" Not sure what that means. Maybe I haven't set something up yet?
Update: I guess I didn't have an SMTP server installed/setup. This tutorial made it really easy for me to get an SMTP server up an running. Now both of the code samples above work.
It sounds like you need to configure an MTA, or find one that you can send to. Ubuntu desktop should set one up by default, probably either exim or postfix, but if you haven't configured it, it will unlikely to be running.
You don't want to set the default transport if you wish to use sendmail (it is the default) and SMTP is different.
That it doesn't send the emails suggests that sendmail or the MTA on your server is not installed/not setup correctly.