0

I am using the FOSUser bundle within my Symfony2 application. I am trying to get the email functionality working but can't get any emails to send successfully.

My development environment is a Ubuntu virtual machine. I tried to use my Gmail account details as described here. I also checked the error logs but nothing regarding the email sending is logged.

I attempted to send a test email using a test controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class TestEmailController extends Controller
{
    public function sendEmailAction()
    {
        $message = \Swift_Message::newInstance()
            ->setSubject('Hello Email')
            ->setFrom('send@example.com')
            ->setTo('me@myemailaddress.com') // use a valid email in actual code...
            ->setBody('yo, wassup!');
        $this->get('mailer')->send($message);

        return $this->render('SysDevPunctualityBundle:TestEmail:sendEmail.html.twig', array(
                // ...
        ));    
    }

}

However this triggers an error with Symfony's web profiler toolbar and I get the following message; "Token "3c494e" was not found in the database."

After some digging around I found this question I followed the suggestion of removing the spool option and also added a 'from_email' option. This made a difference, I am now getting a timeout error:

Connection could not be established with host smtp.gmail.com [Connection timed out #110] 

My guess is that the firewall is blocking the request, I don't know how to find out for sure.

Appreciate if anyone can point me in the right direction.

Community
  • 1
  • 1
Mr B
  • 3,980
  • 9
  • 48
  • 74

2 Answers2

1

I discovered that the source of the problem was that my work firewall was blocking access to the Gmail SMTP server. I switched to another SMTP server (set up by our IT department) and email sending now works fine.

Mr B
  • 3,980
  • 9
  • 48
  • 74
0

Check these two links from the cookbook, to find out how to handle emails while developing: http://symfony.com/doc/current/cookbook/email/dev_environment.html & http://symfony.com/doc/current/cookbook/email/spool.html

Basster
  • 310
  • 1
  • 10