0

I'm trying to send a test email in Symfony 2.7.3 with swiftMailer nevertheless it isn't work. I looked many post even if it isn't work. The regular configuration for this often is:

Controller:

            $message = \Swift_Message::newInstance()
            ->setSubject('Mensaje de prueba')
            ->setFrom('prueba1@gmail.com')
            ->setTo('prueba2@gmail.com')
            ->setBody(
                $this->renderView(
                    'GuiasDocentesAppBundle:FAQ:plantillaEmail.html.twig',
                    array('correoConsultante' => $correoConsultante)
                ),
                'text/html'
            )
        ;
        $this->get('mailer')->send($message);

Parameters.yml:

{ parameters: { 
    database_host: 127.0.0.1, 
    database_port: null, 
    database_name: databasename, 
    database_user: databaseuser, 
    database_password: databasepassword, 
    mailer_transport: gmail, 
    mailer_host: smtp.gmail.com, 
    mailer_user: prueba1@gmail.com, 
    mailer_password: passwordforprueba1, 
    secret: *******************************, 
    database_driver: pdo_mysql, 
    database_path: null } }

config_dev.yml && config.yml:

swiftmailer:
transport: "%mailer_transport%"
encryption: ssl
auth_mode:  login
host:      "%mailer_host%"
username:  "%mailer_user%"
password:  "%mailer_password%"
spool:     { type: memory }

Actually, I'm in development enviroment but I think it isn't a issue. As you can see, prueba1@gmail.com is the same in controller and parameters.yml. The right account (prueba1@gmail.com) have been configured to work with external app without this link I hope somebody can help me. Thanks

drj00003
  • 31
  • 4
  • Also the correct bundle have been added : new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), – drj00003 May 18 '16 at 12:03
  • What is the return value of the send method? Do you have any error in log? – stuzzo May 18 '16 at 13:20
  • Return int(1), no log errors. Can copy the code of object message... – drj00003 May 18 '16 at 14:54
  • Maybe the issue could be the plataform (cloud 9) could not admit it. – drj00003 May 18 '16 at 15:02
  • So Swift Mailer seems to send correctly. Try to comment ```{spool: memory}``` and check your spam folder. – stuzzo May 18 '16 at 15:08
  • Now the system throw the next error: Failed to authenticate on SMTP server with username "prueba1@gmail.com" using 1 possible authenticators – drj00003 May 18 '16 at 15:26
  • Ok, check http://stackoverflow.com/questions/29098781/script-sending-mails-with-gmail-failed-to-authenticate-on-smtp-server. I think that's your exact situation. – stuzzo May 18 '16 at 15:33
  • Thanx, it was the case. In addition to said before, allow access to externals app [link] (https://www.google.com/settings/security/lesssecureapps) I needed entered the captcha phrase [link] (https://www.google.com/accounts/DisplayUnlockCaptcha) – drj00003 May 18 '16 at 16:31
  • Glad to hear that! – stuzzo May 18 '16 at 17:42
  • Thanks so much stuzzo! – drj00003 May 18 '16 at 18:20

1 Answers1

0

In symfony 2.7 i got the same issue in one of my app

Solution was to spool emails http://symfony.com/doc/2.7/cookbook/email/spool.html

And send spooled emails via cron ( lame solution - but works for me)

Michał G
  • 2,234
  • 19
  • 27