2

I've been running a web platform that needs to send a considerable amount of emails daily. At the implementation date I and my partner decided to setup Postfix on the server and use Swift Mailer class to send the email using a SMTP connection to the local Postfix server.

This allowed us to have multiple email accounts, like info@example.com, support@example.com, news@example.com and be able to send email with them correctly signed with DKIM.

My question is, can't we configure PHP in some way to avoid a local SMTP connection (which takes time an server resources) and replace with a more direct way to deliver the messages to be sent to the Postfix queue?

Form my understanding I could use PHP mail() function or even Swift Mailer's Swift_SendmailTransport class and deliver the messages directly to Postfix queue. But if so, how can we ensure DKIM? Will changing the "FROM" header to the email accounts on the local server be enough?

Thank you.

  • 1
    Are you actually having a performance problem? What metrics have you gathered? – Michael Hampton Feb 22 '15 at 2:43
  • When we dispatch a monthly newsletter, about 20k recipients at this time it takes like half an hour or so to dispatch the emails. This disrupts the other normal emails we send with alerts and updates on the platform. – TCB13 Feb 22 '15 at 2:53
  • 3
    If the newsletter isn't time sensitive, use Swift Mailer's Throttler plugin to slow it down. Also consider using third party services like Mandrill to deliver your more time-sensitive transactional email. – Michael Hampton Feb 22 '15 at 3:12
3

Form my understanding I could use PHP mail() function or even Swift Mailer's Swift_SendmailTransport class and deliver the messages directly to Postfix queue.

That's true

But if so, how can we ensure DKIM? Will changing the "FROM" header to the email accounts on the local server be enough?

You doesn't specify your DKIM signer, so I assume that you use OpenDKIM in your setup. OpenDKIM integrate with postfix by milter interface. For signing email from mail() command (without smtp ritual), you need to ensure that OpenDKIM socket/port also listed non_smptd_milters.

  • Yes, I'm using DKIM. So, this question is related to serverfault.com/questions/615686/…. The config there with the right Envelope headers should work fine. Thank you ;) – TCB13 Feb 22 '15 at 5:47
  • * OpenDKIM sorry. – TCB13 Feb 22 '15 at 5:56
2

Firstly, so long as you have OpenDKIM specified in non_smptd_milters as well as smptd_milters in Postfix's main.cf, outgoing mail sent through PHP mail() should still be signed. The Received headers are not signed by default, and nothing much else should have been rewritten by cleanup. If you want an alternative method, you could DKIM sign using Amavis and content_filter, although that means even more SMTP sessions.

Secondly, it sounds unlikely to me that using local SMTP rather than dropping the mail into the maildrop queue is such a performance overhead. It could be that you have a limited number of postfix smtpd daemons all of which are calling the milter, but even without that the mail still has to go through the OpenDKIM milter before being sent out. Yes your PHP scripts will finish sooner, but I doubt the email will be delivered any quicker. It may be worth re-reading http://www.postfix.org/QSHAPE_README.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.