2

I'm going to make my app spool mail, and am trying to find a good place to put the mail spool file.

I like %kernel.cache.dir%/foobarmailspool because it means my (and my fellow developers') existing filesystem ACLs won't need augmentation.

Is writing in app/cache poor form?

If not, is there some naming convention I could/should follow?

On second thought, it's probably not a great idea to spool emails into app/cache, given all the blowing away of the cache that must occur while using symfony2. Still, my question needn't be specific to spooling email, but more about writing to the cache in general (as stated in the title).

Community
  • 1
  • 1
Adam Monsen
  • 9,054
  • 6
  • 53
  • 82

3 Answers3

4

I think it's a bad idea to spool emails in the cache folder because cache is something you can delete at any moment and you can lose not yet sent spooled emails. I recommend creating a separate folder for them — something like app/spool.

Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133
2

Storing them within the cache folder might seem like a good ideea since you already have writing rights there, but all cache locations should be treated as "volatile" and thus unreliable.

If you are just writing them to disk for testing, you can always use /tmp/ or if you are using them in the same execution thread, there is always the well handy I/O streams option within php, more on that at http://php.net/manual/en/wrappers.php.php.

If you want to do it in a production environment however, you would need a real folder on disc with the right permission sets, database, or even memcache if you plan expires well.

Stelian
  • 58
  • 3
  • Good answer. I'm still wondering if there are any conventions for Symfony2's app/cache folder (I think this part got buried in my original post). – Adam Monsen Jul 07 '12 at 06:54
1

If you store the mail in a database you won't need to touch the filesystem at all.

ilanco
  • 9,581
  • 4
  • 32
  • 37
  • True, but is there something built-in to do so, such as [this](http://symfony.com/doc/current/cookbook/email/spool.html)? Not that it's hard to spool emails in a database, but I'd rather not create more code to maintain if I don't have to. – Adam Monsen Jun 11 '12 at 17:19
  • You could create your [own service](http://symfony.com/doc/current/reference/configuration/swiftmailer.html#type) that stores it in a database. – Elnur Abdurrakhimov Jun 11 '12 at 18:22