Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8753393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:24:58+00:00 2026-06-13T13:24:58+00:00

I have written a custom console command to query my database, produce a report

  • 0

I have written a custom console command to query my database, produce a report and e-mail it to an address; however I can not seem to successfully send the e-mail. I can send e-mail fine from within normal controllers elsewhere within my application, and I can also send it from within my console command if I manually create and configure a Swift_Mailer instance and not get it via the container.

Here is a stripped down version of my console command:

<?php

namespace Foo\ReportBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ExpiryCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this->setName('report:expiry')
            ->setDescription('Compile and send e-mail listing imminent expiries');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /* ... */
        $message = \Swift_Message::newInstance()
            ->setSubject('Expiry report')
            ->setFrom('DoNotReply@domain.com')
            ->setTo('recipient@domain.com')
            ->setBody($body);

        $mailer = $this->getContainer()->get('mailer');

/*      This works...
        $transport = \Swift_SmtpTransport::newInstance('smtp.domain.com', 25)
            ->setUsername('username')
            ->setPassword('password');
        $mailer = \Swift_Mailer::newInstance($transport);
*/
        $result = $mailer->send($message);
        $output->writeln($result);
    }
}

Swiftmailer is configured to send via SMTP within my app/config/config.yml file (delivery_address: dev@domain.com is also set in app/config/config_dev.yml):

swiftmailer:
    transport: smtp
    host: smtp.domain.com
    username: username
    password: password
    spool:
        type: memory

When running the command, it prints 1 to the command line, which I assume it means it was successful. However I’m monitoring my mail server’s logs at the same time, and it’s not even connecting.

To confirm that my configuration was being loaded into the mailer, I changed the spool from memory to file and messages are being spooled to the file system when running the command and I can successfully flush the spool on the command line with php app/console swiftmailer:spool:send.

Does anyone have any ideas as to what’s happening here, or any suggestions as to how I can debug it further? Nothing is appearing in my app/logs/dev.log file. I’m using Symfony 2.1.3-DEV.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:24:59+00:00Added an answer on June 13, 2026 at 1:24 pm

    From digging some Symfony and SwiftMailer code, I can see that the memory spool is flushed on the kernel.terminate event that occurs after a response was sent. I’m not sure it works for the commands, but I may be wrong.

    Try adding this code at the end of your command and see if it helps:

    $transport = $this->container->get('mailer')->getTransport();
    if (!$transport instanceof \Swift_Transport_SpoolTransport) {
        return;
    }
    
    $spool = $transport->getSpool();
    if (!$spool instanceof \Swift_MemorySpool) {
        return;
    }
    
    $spool->flushQueue($this->container->get('swiftmailer.transport.real'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a custom class to handle database queries to a remote and
Have you written custom balancers for sharding to balance chunks not using the balancer
I have written a custom launcher in Eclipse which I can access via the
I have written a custom Bindable RichText Box, so I can bind to the
Let's say that I have written a custom e-mail management application for the company
I have written a custom model binder for List in my MVC project however
I have written a custom test harness in Python (existing stuff was not a
I have written a Custom Content Provider on top of a SQLite Database. The
I have written a custom class for overriding the seek method of QSlider. Basically
I have written a custom Django Model Field to store dateutil.relativedelta 's. The field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.