Email can be a pain in the gazoo. Your code works, you've set up dovecot and postfix correctly, and email recipients... are not receiving emails from your application. The most common cause of failure, of course, is spam filters. Depending on the nature of the spam filter, the email might be automatically deleted!
Spam is annoying. For years, ISPs have been doing everything they can to prevent (well, mitigate) spam. One way they do this is to block outgoing traffic on Port 25 (the default port for SMTP email). Unfortunately, when I set up Postfix, I used the default settings — because getting email to work was much tougher than I expected and I didn't want to make things any more interesting than I had to!
With Postfix installed, I can now install Dovecot, the Mail Delivery Agent that creates a POP3 and IMAP server, which allows users to download their email from the server.