I am using gmail as an smtp server for my swiftmailer class.
however I am getting
Expected response code 220 but got code "", with message "" in "\classes\Swift\Transport\AbstractSmtpTransport.php"
What does this mean?
I think it probably means you sent a blank line to the smtp server.
Make sure none of your commands have line feeds in them.
Can you log the transaction and paste a copy of the log?
see here for details about logging
http://swiftmailer.org/docs/logger-plugin
I got this when I had the wrong setting in the factories.yml file as below.
class: Swift_SendmailTransport
But it should be the following.
class: Swift_SmtpTransport
For users of smtp-relay.gmail.com, if you use localhost/127.0.0.1 as domain during developments, you probably need to change the domain name to use in EHLO command to begin the transaction.
For SwiftMailer Symfony bundle (since 2.4.0), you can set the local_domain config parameter:
// config/packages/dev/swiftmailer.yaml
swiftmailer:
...
local_domain: dev.mydomain.tld
Related
In my .env file I have:
MAILER_URL="smtp://localhost:25?encryption=&auth_mode="
But if I send a mail the log shows:
Could not send mail: Failed sending mail to following recipients: {{ recipients }} with Error: Unable to connect with STARTTLS. Error Code:0 Template data ...
Looks like it tries to use TLS but I don't want to. It worked before. Maybe it got broken by an update.
Looking at the documentation I also tried encryption=null with same result.
Debugging in vendor/shopware/core/Content/Mail/Service/MailerTransportFactory.php:36 I made sure my MAILER_URL was used.
I am using shopware 6.4.1.1 with symfony/mailer v5.2.10
How can I get mails working again?
By default, the SMTP transport in the Symfony Mailer performs TLS peer verification. You can disable this verification by setting the parameter verify_peer to 0, for example:
MAILER_URL="smtp://localhost:25?encryption=&auth_mode=&verify_peer=0"
SwiftMailer is the default way of sending email from a Symfony 2 project, and I'd like to use it in an application. I've pointed it towards the SMTP server provided by my internet provider (Virgin Media, in the UK), but my emails are not successfully sent. The exception thrown says
Expected response code 250 but got code "501", with message "501 HELO requires valid address
in response to the SMTP command
HELO [::1]
[::1] corresponds to localhost in IPv6, and it's not that surprising that the SMTP server would reject that if it's expecting a proper domain name. Tracing execution through the Swiftmailer source, I find that this value comes from _domain on AbstractSmtpTransport; altering the value during the debug session allows the email to be sent. Although it can be set using the public setLocalDomain() method, it isn't anywhere in the Symfony 2 framework, so it seems that there is no way (obvious to me, at least) of easily configuring this value simply by, for example, changing a Symfony config file.
So my question is this: is there some other way of changing this value, ideally using config, without my diving into the Symfony code and changing bits that aren't meant to be changed? And if so, what?
From inside a Symfony controller, you can configure the HELO/EHLO name like that:
$this->get('swiftmailer.transport')->setLocalDomain('your.domain');
Unfortunately no.
The code for get the local domain in SwiftMailer is:
/** Try to determine the hostname of the server this is run on */
private function _lookupHostname()
{
if (!empty($_SERVER['SERVER_NAME'])
&& $this->_isFqdn($_SERVER['SERVER_NAME']))
{
$this->_domain = $_SERVER['SERVER_NAME'];
} elseif (!empty($_SERVER['SERVER_ADDR'])) {
$this->_domain = sprintf('[%s]', $_SERVER['SERVER_ADDR']);
}
}
So, is guessed and it's server configuration.
I opened an issue for SwiftMailer to do this:
https://github.com/swiftmailer/swiftmailer/issues/453
UPDATE: The issue has been resolved on Feb 27th 2018.
I've got a symfony1 application with following factories.yml file:
mailer:
param:
delivery_strategy: realtime
transport:
class: Swift_SmtpTransport
param:
host: smtp.gmail.com
port: 465
encryption: ssl
username: my.user#gmail.com
password: my_password
password and username is correct, because I can use them to simply log in to gmail. I'm having trouble with symfony/swift mailer using gmail smtp to send mail. I'm submitting correct username/password, but google blocks, saying that the server is in Russia (giving the IP) and it says it doesn't trust it blah blah blah in case this was a security attack. Anyway, it's me and I just want to send emails using gmail.
The original gmail warning-email is in Polish, the translated version goes like this:
Someone recently used your password to log in to your Google Account
my.user # gmail.com. This person has received an
application (such as a client e-mail) or mobile device.
We blocked the logon attempt, in case someone wanted to break in to
your account. Check out these information:
Thursday, 12 December 2013 8:13:15 UTC IP address: 62.212.65.74
(s99.linuxpl.com.) Location: Russia
If you do not recognize the login attempts, someone else might try to
access your account. As soon as you log in and reset your password.
If this is you and you are having trouble accessing your account,
follow the troubleshooting instructions available on
http://support.google.com/mail?p=client_login
Regards, Google Accounts Team
And the link explains how to use smtp clients just like thunderbird, but it says nothing about software like swift mailer.
The symfony debug environment shows following error code:
Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required. Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 a51sm103278568eeh.8 - gsmtp
Does anyone know what can I do?
It seems strange, because there's no information about this at mentioned google links, but somehow I managed to find this information on the web:
you may try to visit https://accounts.google.com/DisplayUnlockCaptcha which displays a button that allows this gmail account to be accessed from a distant machine/device (other than the one you're just logged in now). I've pressed the button and retried mail sending and everything works now (the configuration remained 100% the same).
Hope it helps someone.
In my case it was a issue with security refer below
https://www.google.com/settings/security/lesssecureapps
i am trying to use localhost to send mail. however, i am getting this error when sending:
Warning: mail() [function.mail]: SMTP server response: 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1). i have smtp settings correct in php.ini and am just confused as to what this means. thanks
There seem to be two primary reasons for this.
The first has to do with the email client configuration (google INVALID HELO OUTLOOK).
The other reason is an improperly configured SMTP server where the server sends out emails with only the server name and not a fully qualified name (e.g., emailserver vs emailserver.mydomain.com).
You should contact your hosting company and give them as much detail as you can. They should be able to help.
If you are using cPanel, you can disable HELO checking. See the user guide. The trade off is you will receive more spam...
I had a similar problem with postfix in Ubuntu. It turned out that I'd not set 'myhostname' in the postfix configuration file.
The problem disappeared when I configured 'myhostname' in the following file:
/etc/postfix/main.cf
When I send an email with the PHP Swift mailer to this server: smtp.exchange.example.com like this:
// Load transport
$this->transport =
Swift_SmtpTransport::newInstance(
self::$config->hostname,
self::$config->port
)
->setUsername(self::$config->username)
->setPassword(self::$config->password)
;
// Load mailer
$this->mailer = Swift_Mailer::newInstance($this->transport);
// Initialize message
$this->message = Swift_Message::newInstance();
// From
$this->message->setFrom(self::$config->from);
// Set message etc. ...
// Send
$this->mailer->send($this->message);
I get a strange error back:
Failed to authenticate on SMTP server with username "user#example.com" using 2 possible authenticators
I know for sure that the login-info is correct.
This might be old but somebody might get help through this. I too faced the same problem and received a mail on my gmail account stating that someone is trying to hack your account through an email client or a different site.
THen I searched and found that doing below would resolve this issue.
Go to https://accounts.google.com/UnlockCaptcha‎
and unlock your account for access through other media/sites.
UPDATE : 2015
Also, you can try this, Go to https://myaccount.google.com/security#connectedapps
At the bottom, towards right there is an option "Allow less secure apps". If it is "OFF", turn it on by sliding the button.
UPDATE : 2021
The google URL has now changed to : https://myaccount.google.com/lesssecureapps. You will be asked to relogin
I had the same issue, so I've disabled one setting on my WHM root login, which is as follows :
WHM > Home > Server Configuration > Tweak Settings > Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak) [?]
I really have the same problem, finally, i solved it.
its likey not the Swift Mail's problem. It's Yaml parser's problem.
if your password only the digits, the password senmd to swift finally not the same one.
swiftmailer:
transport: smtp
encryption: ssl
auth_mode: login
host: smtp.gmail.com
username: your_username
password: 61548921
you need fix it with double quotes
password: "61548921"
I just received the same error.
The strange thing is that commented the credential lines
// ->setUsername(self::$config->username)
// ->setPassword(self::$config->password)
And the problem disappeared.
I'm puzzled because the mail server definitely needs those credentials.
I tried almost all the possible suggestions mention here but for me problem got solved after changing "Access for less secure apps" to ENABLE in my Google account security settings tab. Hope this might useful for others !
The server might require some kind of encryption and secure authentication.
see http://swiftmailer.org/docs/sending.html#encrypted-smtp
try putting username in double quote "username", somehow that fixed for me.
I faced the same problem and solved it. Try to log in manually to your gmail account first.
This issue is due to google has detected your gmail account has been abusing. E.g send a lot of emails over a short period of time.
You perhaps use the wrong username.
I had a similar error. Ensure you're not using uppercase while logging into server.
Example: JacekPL#lala.pl
If you use ->setUsername('JacekPL'), this can cause an error. Use ->setUsername('jacekpl') instead. This solved my problem.
First check if there is any connectivity problem and you can reach the SMTP server:
In terminal type:
telnet servername portnumber
If you receive the 220 response you can reach the SMTP server and there is no connectivity problem but if the connection to the server failed see what's wrong in your network.
If the server needs auth try to authenticate on the server by username and password and see if something goes wrong.
At last see if the server requires encryption and if yes openssl and other stuff are configured correctly.
I got the same same error.
I was using gmail account and Google's SMTP server to send emails. The problem was due to SMTP server refusing to authorize as it considered my web host (through whom I sent email) as an intruder.
I followed Google's process to identify my web host as an valid entity to send email through my account and problem was solved.
If you are trying to send mail from your local enviroment eg. XAMPP or WAMP, this error will occur everytime, go ahead and try the same code on your web hosting or whatever you are using for production.
Also, 2 step authentication from google may be the issue.
Strange enough sending emails works again. We did not change anything and the host say they did not either. We think a server restarts or so. It is strange :S