Having troubles to send mails in 1and1 hosting - php

I have a 1and1 account, im trying to send emails with symfony2.3 and swift_mailer but it is impossible.
I'm not having any error, i already check the symfony logs, but nothing.
This is my implemtation(in a Action):
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('test#domain.com')
->setTo('myuser#mydomain.com')
->addCc('other#mydomain.com')
->setBody( "test body" )
;
$mailer = $this->get('mailer');
$result = $mailer->send($message, $fails);
//$fails receive a empty array
//$result get value 1
This is the configuration:
swiftmailer:
transport: smtp #i also try mail and sendmail
host: smtp.1and1.mx #i also try smtp.1and1.es, auth.smtp.1and1.fr
username: someone#mydomain.net #the complete email someone#mydomain.net(this account is active, i'm able to login in webmail...)
password: mypass
spool: { type: memory }
encryption: tls # i also try without this setting
Nothing work, even, i try with gmail configuration:
swiftmailer:
transport: gmail
host: smtp.gmail.com #with and without this parameter
username: %mailer_user% #the complete email someone#gmail.com and without domain
password: %mailer_password% #the gmail password
and same result.
What im doing wrong?
1and1 support just send me this link:
http://faq.1and1.es/email/email/informacion_email/9.html
Update:
If i remove { type: memory } in the configuration i got this error:
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.1and1.es [Connection refused #111]...
Any help?

Instead mail.php, go to .env and set MAIL_DRIVER property. This work on 1and1.
MAIL_DRIVER=mail
MAIL_HOST=smtp.1and1.es
MAIL_PORT=25
MAIL_USERNAME=<xxxxxx#xxxx>
MAIL_PASSWORD=<xxxxxx>
MAIL_ENCRYPTION=tls

We had issues with Swiftmailer not sending emails when using the memory spool. We ended up changing to a file spool and then setting up a cron job to execute the swiftmailer command to send it out (app/console swiftmailer:spool:send -e=prod)

Edit: deleted tard answer and added this other one:
If your SMTP password contains # symbol it can cause the .env file to fail if you don't use quotes

Related

Symfony - "503 5.5.2 Need rcpt command" message when sending mail with Swiftmailer to external addrress

I'm trying to send emails through swiftmailer in a Symfony 4 application. Here is my swiftmailer.yaml config file :
swiftmailer:
mailers:
mailer_smtp:
url: '%env(MAILER_URL)%'
spool: { type: 'memory' }
transport: smtp
host: xxxxxxxxxxxxxx
port: 25
encryption:
username:
password:
auth_mode: login
default_mailer: mailer_smtp
I can send emails to local addresses only, when I try to send an email to an external address I get this :
app.ERROR: Exception occurred while flushing email queue: Expected response code 354 but got code "503", with message "503 5.5.2 Need rcpt command "
I have another PHP application (not using Symfony or swiftmailer) that send emails to any address (local or external) with a similar configuration :
connection on port 25, no auth required. This is allowed on our exchange server, as long as the source IP is authorized.
I changed my swiftmailer.yaml this way :
swiftmailer:
mailers:
mailer_smtp:
url: '%env(MAILER_URL)%'
spool: { type: 'memory' }
transport: smtp
host: xxxxxxxxxxxxx
port: 25
encryption:
username: xxxxxxxx#xxxxx.xx
password: xxxxxxx
auth_mode: login
default_mailer: mailer_smtp
And then I get this error, to any address (external or local email) :
app.ERROR: Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "xxx" using 0 possible authenticators. [] []
If the fonction that sends the email, I'm using in the SetFrom property the same user I filled in swiftmail.yaml :
$message = (new Swift_Message($evenement->getNomEvenement()))
->setFrom("xxxxxxxx#xxxxx.xx")
->setTo($mail)
Do you have any idea to solve this?
Thanks for your help

Symfony3 - Email not sent from a Command

I can't sent e-mail from a Command in Symfony3 in prod.
My code :
$message = \Swift_Message::newInstance()
->setSubject('A subject')
->setFrom('email#site.com')
->setTo('email#site.com')
->setBody('content', 'text/html');
$mailer = $this->getContainer()->get('mailer');
$mailer->send($message);
Config.yml
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
port: '%mailer_port%'
encryption: '%mailer_encryption%'
spool: { type: memory }
Parameters.yml
mailer_transport: smtp
mailer_host: myhostfromovh
mailer_encryption: null
mailer_port: 587
mailer_user: myuser
mailer_password: mypassword
I got no error but no e-mail received in my mailbox. :(
Moreover, when I write in command line :
php app/console swiftmailer:email:send
I got :
[2017-12-22 13:31:12] app.ERROR: Exception occurred while flushing email queue: Connection could not be established with host myhostfromovh [Connection refused #111]
I changed my custom host myhostfromovh by smtp.gmail.com or ns0.ovh.net (with PORT and USER / PASSWORD), nothing to do, it doesn't work. :-(
BUT ! When I execute the same code in a Controller, no problem, I receive the mail. So I don't understand.
Help me ! \o/
You have enabled an email queue in your swiftmail this means that the emails will be queued and send during the kernel event terminate (after you already send the response to the client).
You should have the errors of your controller on var/logs/prod.log
It seems your host is not allowed to connect to that host:port. Possible reasons?
Your IP has been banned
Wrong ip/port (Configuration)
Service provider/Enterprise/University firewall block outgoing smtp connections (quite common nowadays)
Install mailcatcher https://mailcatcher.me/ and try to send emails to your local smtp server.

Swiftmailer sending from console but not from PHP

I have the following code to send mails:
/* Emails */
$message = \Swift_Message::newInstance()
->setSubject('Ihre Sammelrechnung')
->setFrom("xxx#myserver.com")
->setTo("recipient#gmail.com")
->setBody(
$this->renderView(
'email/invoiceMultiFinal.html.twig', array(
'company' => 'COMPANY',
)
),
'text/html'
);
/* Send eMail */
if(!$this->get('mailer')->send($message)){
die("ERROR");
}
I know 100% that sender an recipient are correct. In my Logs I have:
{"message":"Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username \"xxx#myserver.com\" using 1 possible authenticators","context":[],"level":400,"level_name":"ERROR","channel":"app","datetime":{"date":"2016-05-31 15:19:09.919207","timezone_type":3,"timezone":"Europe/Berlin"},"extra":[]}
config.yml
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory } #Deleting this changes nothing
parameters.yml
parameters:
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: xxx#myserver.com # adding "" doesn't change sth either
mailer_password: password
secret: xxxxxxx
I am using my own server, so no Gmail etc. involved. I can send and receive emails through the webmailer AND through php bin/console swiftmailer:email:send
Any ideas what can cause such behaviour? Side note, it worked like a charm for almost a month! It stopped today, possibly related to a reboot!

PHP Swiftmailer with Zoho smtp server not sending mail

I'm using Swiftmailer on a Symfony2. I'm also using Zoho mail to host my mail server and I have configured Swiftmailer using the smpt details provided by Zoho, but it looks like something is wrong because the following exception is thrown:
PHP Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host 127.0.0.1 [Connection refused #111]'
My parameters.yml file looks like:
parameters:
mailer_transport: smtp
mailer_host: smtp.zoho.com
mailer_port: 465
mailer_encryption: ssl
mailer_user: my_username
mailer_password: my_password
mailer_authmode: plain
and my config.yml:
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
port: "%mailer_port%"
encryption: "%mailer_encryption%"
username: "%mailer_user%"
password: "%mailer_password%"
auth_mode: "%mailer_authmode%"
spool: { type: memory }
I have tested the connection using telnet and everything seems to be alright:
root:/# telnet smtp.zoho.com 465
Trying 74.201.154.90...
Connected to smtp.zoho.com.
Escape character is '^]'.
What am I missing?
Thanks!
Well, if you parameters.yml is well loaded then i think i know the problem where it comes from, i think your webhost doesn't allow ssl connection port 465, it refuses the connection thats what the error 111 means, try first to connect using TLS security with port 587. If you still want to use 465 try contacting your web hosting to check that port.
Edit :
Remove the "" should fix it
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
port: %mailer_port%
encryption: %mailer_encryption%
username: %mailer_user%
password: %mailer_password%
auth_mode: %mailer_authmode%
spool: { type: memory }
Change mailer_authmode: plain to mailer_authmode: login.
After trying with all the solutions (in my development and the production machine) I've tryied PhpMailer. It works perfectly.
I think the problem is in SwiftMailer's code.
You need to log into zoho and set up an application specific password. You can find it under Security -> Two Factor Authentication. Use that password instead of your account password.
Please note that Zoho Mail does not offer IMAP/POP support anymore with their free plan:
```
FREE PLAN
Up to 25 Users
5GB* /User, 25MB Attachment Limit
Webmail access only+. Single domain hosting.
```
+IMAP/POP Support Available exclusively with the paid plans.
https://www.zoho.com/workplace/pricing.html?src=zmail
Old free plans (registered before 2018???) seem to still have IMAP/POP Support Available
Source: https://help.zoho.com/portal/community/topic/zoho-free-tier-pop-imap-activesync-no-longer-free

symfony2: emails are not sent

$mail = \Swift_Message::newInstance()
->setSubject($message->getSubject())
->setFrom($message->getEmail())
->setBody($message->getBody());
$this->get('mailer')->send($mail);
Mails are not sent when using swiftmailer. Yet, when I go step by step in the debugger, it seems to send the email and returns sent=1. However I don't receive anything in my mailbox (gmail). I use my gmail account for sending emails, as shown below:
parameters:
mailer_transport: gmail
mailer_host: ~
mailer_user: username#gmail.com
mailer_password: my-password
delivery_address: username#gmail.com
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
I've checked apache error log, nothing. I've run php app/console swiftmailer:spool:send just in case, but no luck.
What could prevent emails from being sent ?
You need either to:
1) Remove the spool line in your swiftmailer configuration, this one:
spool: { type: memory }
2) Trigger the spool queue to be sent:
php app/console swiftmailer:spool:send
But I think you are looking for option 1)
u can try this one...
Parameter.yml
mailer_transport: gmail
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: 'xxxxxxxxxxxx'
config.yml
swiftmailer:
transport: gmail
host: smtp.gmail.com
username: 'Yourmail-id#gmail.com'
password: 'Password'
The ->setTo part was missing ! That solved it.
$mail = \Swift_Message::newInstance()
->setSubject($message->getSubject())
->setFrom($message->getEmail())
->setTo("me#gmail.com")
->setBody($message->getBody());
First, when you set spool: { type: memory } it means that you actually want to send the emails manually by running the spool command: php app/console swiftmailer:spool:send. So removing that spool line is going to help.
Second, you need to properly configure your mailing host. For development purposes, I strongly recommend that you use a service such as SendGrid and configure it as detailed in this Symfony2 Mailing Setup Tutorial
The tutorial also contains details on how to properly setup a mailing service in Symfony2 and how to build mailing templates.
Third, if you want to stick with Gmail, then the correct data is:
mailer_transport: smtp
mailer_host: smtp.gmail.com
mailer_user: your_gmail_address#gmail.com
mailer_password: 'your_gmail_password'
mailer_port: 587

Categories