Not the right category, but I’m not sure which is best, so will let a moderator deal with that.
A good discussion of the FreePBX side of this can be found at Initiate outgoing call from a script
This is probably not the best place for the email side, and you haven’t said how the mailboxes are accessed.