Swiftmailer does not send from Hyper-V virtual machine - symfony

A Hyper-V machine with Ubuntu 18 has a Symfony 4.3 app with SwiftMailer. Attempts to send an email from the command line with php bin/console swiftmailer:email:send result in
[OK] 1 emails were successfully sent.
although mail.log contains this
localhost sm-mta[5847]: xBBFThub005847: localhost [127.0.0.1] did not
issue MAIL/EXPN/VRFY/ETRN during connection to MTA-v4
and the email is never received.
.env.local contains
MAILER_URL=gmail://username#gmail.com:password#localhost?encryption=tls&auth_mode=oauth
.../config/packages/swiftmailer.yaml:
swiftmailer:
default_mailer: memory
mailers:
memory:
sender_address: 'admin#bogus.info'
transport: smtp
spool: { type: 'memory' }
spooler:
sender_address: 'admin#bogus.info'
transport: smtp
spool:
type: file
path: '%kernel.project_dir%/var/spool'
Using the identical configuration from the host DOES deliver mail.

While the eventual solution may be excessive it is effective. I first tried installing sendmail but that went nowhere. Purged it and installed postfix following this tutorial on using postfix to relay to gmail. When a test message failed I followed the answer provide by kjones at this site. Allowed "Access for less secure apps setting" at gmail and all is now well.
All this for a practice go-live run!

Related

Problem with sending emails in Heroku using Swiftmailer

I wrote an application in symfony 4.
I deployed it on the heroku.
Everything works as it should with the exception of sending emails.
When I trying to send an e-mail from the console like this:
heroku run php bin/console swiftmailer:email:Send
Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "healthcard95#gmail.com" using 1 possible authenticat
ors. Authenticator LOGIN returned Swift_TransportException: Expected response code 235
Please log in via your web browser and then try again.
Learn more at https://support.google.com/mail/answer/78754 i65sm11848023qkh.49 - gsmtp
" in /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457
This is my swiftmailer.yaml file:
swiftmailer:
transport: gmail
username: username
password: ********
host: localhost
port: 465
encryption: ssl
auth-mode: login
spool: { type: 'memory' }
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
verify_peer_name: false
How to fix this error?
The problem is in Gmail.
Although I have set up security to allow less secure applications and e-mails from local hosts are sent correctly when I perform the same operation in gmail heroku, I see a new device - unfortunately I can't add it to trusted devices, therefore it's blocked.
The solution was to change mail, e.g. on yandex.com.
Here is an example file swiftmailer.yaml correctly configured for heroku:
swiftmailer:
transport: smtp
username: username
password: ********
host: smtp.yandex.com
port: 465
encryption: ssl
auth-mode: login
spool: { type: 'memory' }
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
verify_peer_name: false

How can I send emails using Symfony, Swift Mailer, and Office 365?

I'm using Symfony 3.4 deployed in HostGator. I need send emails to my users in some cases. If I use Gmail, the emails are sent without problem, but when I use Office 365, I'm getting the following error:
Connection could not be established with host
This is my email configuration:
parameters:
mailer_transport: smtp
mailer_host: ''
mailer_user: example#mydomain.co
mailer_password: 'mypassword'
mailer_port: '587'
mailer_smtp: 'smtp.office365.com'
I would try pasting the 'smtp.office365.com' for the field: mailer_host
Use host instead of mailer_smtp. I have this configuration for my swiftmailer. Hope it works for you.
# Swiftmailer Configuration
swiftmailer:
transport: 'smtp'
host: '%mailer_host%' // in your case : 'smtp.office365.com'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }

"Connection could not be established with host smtp.gmail.com". Symfony. Swiftmailer

I got exception:
Connection could not be established with host smtp.gmail.com
Same exception in old project Symfony2.8 and newest Symfony3.
I can ping smtp.gmail.com.
The Avast Antivirus was guilty.
In Google "Account settings" enable "Access for less secured apps" by setting it to "Allow".
Mailer host is your localhost or 127.0.0.1. It's not smtp.google.com
I'm using this configuration for my localhost application
parameters:
mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_user: youremail#gmail.com //replace by your gmail account
mailer_password: ********** //replace by your gmail password
config.yml:
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
your controller code seems to be the same as mine.
As napestershine said in his response do not forget to allow less secure app on your gmail account.

Symfony 2 and Swiftmailer not working with file spooling

I can't get the file spooling to work properly with Symfony 2 and Swiftmailer.
This is my config
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool:
type: file
path: '%kernel.root_dir%/spool'
port: %mailer_port%
encryption: %mailer_encryption%
sender_address: %mailer_sender_address%
When I send an email, a file is created in app/spool/default/
I then run
php app/console swiftmailer:spool:send
and get this response
[2015-12-29 18:54:40] Processing default mailer... 1 emails sent
So it looks like it has worked, but nothing is sent and /var/log/mail.log does not show any new emails.
When I had the config set to memory spooling, the emails were working without any issue, all I changed was config.yml
swiftmailer:
spool: { type: memory }
changed to
swiftmailer:
spool:
type: file
path: '%kernel.root_dir%/spool'
I'm using sendgrid and postfix to actually send out the emails, but I'm not sure that the emails are even getting to postfix, so that probably doesn't make any difference.
The problem ended up being the default environment. All I needed to do was specify an environment other than dev
php app/console swiftmailer:spool:send --env=prod

Symfony2, send mail to gmail

I want to intercept all email send by Symfony2.
I configure swiftmailer like that:
swiftmailer:
delivery_address: my#gmail.com #My gmail addr
transport: gmail
username: my#gmail.com#I use my gmail for easy smtp configuration (just for dev)
password: mypassword
I receive no emails. I'm developping on Windows10 and i use Wamp.
I guess you in dev mode, so you need to do this in you config_dev file:
# app/config/config_dev.yml
swiftmailer:
disable_delivery: false
delivery_address: dev#example.com
I guess you put your conf in config.yml file. You have to check in config_prod and config_dev if the "delevery_address" param is not overidden.

Resources