MacOS – “Natively” add emails to Mail by PHP pipe script

emailmacosmail.appPHP

I found this awesome tutorial on how to send emails on localhost that will open your Mail showing you the email that was sent from PHP, however this is slightly annoying getting Mail to open when an email is sent – I have some tasks that run in the background which sends an email for development reasons for my site so I can test the emails.

I want to be able to not get annoyed by getting popped up with emails, instead I would like it to pipe it to Mail and show in my inbox when I click "Get new messages" so I can look into the email whenever I want not at the instant when the email is sent.

I've looked into where Mail stores their email ~/Library/Mail/V2, I was wondering if I could adjust the script to add the email there, but it looks quite complication so I don't want to risk having any confusion or corruption happening.

Is there any possibility to store the mails without any problems so Mail can add it to my inbox list via PHP?

Anything?

Best Answer

You can do what you ask, but it requires a Mailbox > Rebuild operation. That asks Mail to scan the ~/Library/Mail directory you found and rebuild its email header database from the files it finds there. I doubt you'd find that acceptable.

I'm afraid Gerry's comment above is the right way to go about this: set up a test email account somewhere, use one of the many PHP-to-SMTP methods you can find online, and point Apple Mail at that email account.

Perhaps the simplest, most Apple-like way to achieve that end is with OS X Server. It gives you a configuration UI for the Postfix SMTP mail server built into OS X. Setup through the Server GUI is about as easy as you can hope for. You can create a private user account, and be assured that your test emails won't ever even leave the machine. As cheap as OS X Server is these days, it's pretty much a no-brainer.

If you absolutely have to do this for no cost, you can configure Postfix by hand. The configuration GUI you get with OS X Server is helpful, but not strictly necessary.