symfony / swiftmailer-bundle

Symfony Swiftmailer Bundle
https://symfony.com/swiftmailer-bundle
MIT License
1.56k stars 151 forks source link

swiftmailer:spool:send throws error "Swift_IoException: Failed to create cache directory" #210

Closed azine closed 4 years ago

azine commented 6 years ago

Hi all,

I have a cron job that executes the swiftmailer:spool:send command every minute. When I try to send a few hundred emails "at once", sometimes I get the following exception:

[2017-05-18 16:42:48] app.ERROR: Swift_IoException: Failed to create cache directory /tmp/c0f3309b4e8d55c9c726177eea460555 (uncaught exception) at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php line 274 while running console command `swiftmailer:spool:send`
Swift_IoException: Failed to create cache directory /tmp/c0f3309b4e8d55c9c726177eea460555
    at Swift_KeyCache_DiskKeyCache._prepareCache(c0f3309b4e8d55c9c726177eea460555)[DiskKeyCache.php:274]
    at Swift_KeyCache_DiskKeyCache.setString(c0f3309b4e8d55c9c726177eea460555, body,
iVBORw0KGgoAAAANSUhEUgAAAAoAAAABCAYAAADn9T9+AAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QQIDi0H5pDJOAAAABZJREFUCNdjZIAARjTMhEQzMzAw
sAIAARMAE51tzwcAAAAASUVORK5C, 2)[DiskKeyCache.php:86]
    at Swift_KeyCache_SimpleKeyCacheInputStream.write(
iVBORw0KGgoAAAANSUhEUgAAAAoAAAABCAYAAADn9T9+AAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QQIDi0H5pDJOAAAABZJREFUCNdjZIAARjTMhEQzMzAw
sAIAARMAE51tzwcAAAAASUVORK5C)[SimpleKeyCacheInputStream.php:60]
    at Swift_ByteStream_AbstractFilterableInputStream._doWrite(
iVBORw0KGgoAAAANSUhEUgAAAAoAAAABCAYAAADn9T9+AAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QQIDi0H5pDJOAAAABZJREFUCNdjZIAARjTMhEQzMzAw
sAIAARMAE51tzwcAAAAASUVORK5C)[AbstractFilterableInputStream.php:176]
    at Swift_ByteStream_AbstractFilterableInputStream.write(iVBORw0KGgoAAAANSUhEUgAAAAoAAAABCAYAAADn9T9+AAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QQIDi0H5pDJOAAAABZJREFUCNdjZIAARjTMhEQzMzAw
sAIAARMAE51tzwcAAAAASUVORK5C)[AbstractFilterableInputStream.php:92]
    at Swift_Mime_ContentEncoder_Base64ContentEncoder.encodeByteStream(Swift_ByteStream_FileByteStream, Swift_Transport_StreamBuffer, 0, 78)[Base64ContentEncoder.php:86]
    at Swift_Mime_SimpleMimeEntity._bodyToByteStream(Swift_Transport_StreamBuffer)[SimpleMimeEntity.php:547]
    at Swift_Mime_SimpleMimeEntity.toByteStream(Swift_Transport_StreamBuffer)[SimpleMimeEntity.php:522]
    at Swift_Mime_SimpleMimeEntity._bodyToByteStream(Swift_Transport_StreamBuffer)[SimpleMimeEntity.php:562]
 ... 19 more
 {"exception":"[object] (Swift_IoException(code: 0): Failed to create cache directory /tmp/c0f3309b4e8d55c9c726177eea460555 at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php:274)"} []

  [Swift_IoException]
  Failed to create cache directory /tmp/c0f3309b4e8d55c9c726177eea460555

Exception trace:
 () at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php:274
 Swift_KeyCache_DiskKeyCache->_prepareCache() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php:86
 Swift_KeyCache_DiskKeyCache->setString() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php:60
 Swift_KeyCache_SimpleKeyCacheInputStream->write() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php:176
 Swift_ByteStream_AbstractFilterableInputStream->_doWrite() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php:92
 Swift_ByteStream_AbstractFilterableInputStream->write() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php:86
 Swift_Mime_ContentEncoder_Base64ContentEncoder->encodeByteStream() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php:547
 Swift_Mime_SimpleMimeEntity->_bodyToByteStream() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php:522
 Swift_Mime_SimpleMimeEntity->toByteStream() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php:562
 Swift_Mime_SimpleMimeEntity->_bodyToByteStream() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php:522
 Swift_Mime_SimpleMimeEntity->toByteStream() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php:562
 Swift_Mime_SimpleMimeEntity->_bodyToByteStream() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php:522
 Swift_Mime_SimpleMimeEntity->toByteStream() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php:614
 Swift_Mime_SimpleMessage->toByteStream() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Message.php:172
 Swift_Message->toByteStream() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:327
 Swift_Transport_AbstractSmtpTransport->_streamMessage() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:428
 Swift_Transport_AbstractSmtpTransport->_doMailTransaction() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:444
 Swift_Transport_AbstractSmtpTransport->_sendTo() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:176
 Swift_Transport_AbstractSmtpTransport->send() at /var/www/acmeApp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/FileSpool.php:169
 Swift_FileSpool->flushQueue() at /var/www/acmeApp/vendor/symfony/swiftmailer-bundle/Command/SendEmailCommand.php:108
 Symfony\Bundle\SwiftmailerBundle\Command\SendEmailCommand->recoverSpool() at /var/www/acmeApp/vendor/symfony/swiftmailer-bundle/Command/SendEmailCommand.php:83
 Symfony\Bundle\SwiftmailerBundle\Command\SendEmailCommand->processMailer() at /var/www/acmeApp/vendor/symfony/swiftmailer-bundle/Command/SendEmailCommand.php:62
 Symfony\Bundle\SwiftmailerBundle\Command\SendEmailCommand->execute() at /var/www/acmeApp/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:261
 Symfony\Component\Console\Command\Command->run() at /var/www/acmeApp/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:857
 Symfony\Component\Console\Application->doRunCommand() at /var/www/acmeApp/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:188
 Symfony\Component\Console\Application->doRun() at /var/www/acmeApp/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:90
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/acmeApp/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:119
 Symfony\Component\Console\Application->run() at /var/www/acmeApp/app/console:22

swiftmailer:spool:send [--message-limit MESSAGE-LIMIT] [--time-limit TIME-LIMIT] [--recover-timeout RECOVER-TIMEOUT] [--mailer MAILER] [--transport TRANSPORT]

I suspect that it is a concurrency issue. The command instance started at x is still running (sending emails) when the next command instance is started at x+1minute.

Do you think that might be true? I think my proposed PR #209 would fix the problem.

mhunesi commented 4 years ago

I have same problem. Yii2 queue mailer.

`[2013] YarCode\Yii2\QueueMailer\Jobs\SendMessageJob (attempt: 1, PID: 2534) is finished with error: yii\base\ErrorException: mkdir(): No such file or directory in /var/www/html/app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php:274 Stack trace:

0 [internal function]: yii\base\ErrorHandler->handleError(2, 'mkdir(): No suc...', '/var/www/html/a...', 274, Array)

1 /var/www/html/portal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php(274): mkdir('/var/folders/lp...')

2 /var/www/html/app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php(86): Swift_KeyCache_DiskKeyCache->_prepareCache('61dc1947268a634...')`

ShaneJohnsonCC commented 3 years ago

This is closed but has no solution listed... @mhunesi did you find the solution?

shashankdevstree commented 2 years ago

anyone find solution?

ShaneJohnsonCC commented 2 years ago

@shashankdevstree I've given up. Honestly, I don't think Swiftmailer is meant for mass mailing. But even then, even single emails generated from server (even sent with SMTP) are sent to spam/junk folders for me. AND some endpoint refuse to even accept the email. We have countless reports from our user base with these issues. This is why we have completely moved away from Swiftmailer and integrated with a professional CRM. I would encourage the same thing. You will be much more pleased in the long run

shashankdevstree commented 2 years ago

Can understand your concern @ShaneJohnsonCC In my case I was getting an error of not being able to create a directory under the TEMP folder on the ubuntu system that's why I changed the path of the temp folder on my ubuntu system and it works fine again by sending an email.