haraka-plugin-resque v1.1.7
haraka-plugin-resque
Haraka plugin that act as a queue and perform REST post to a remote url.
Ideal Setup
You're a SASS Provider (such as form submission like Wufoo) requiring to send email on-behalf-of client.
USAGE
SMTP-Client -> Haraka -> API -> Working-SMTP Server - using a different email sends on-behalf-of/sends-as your Client.
This plugin pushes your email to a REST API.
cd /path/to/local/haraka
npm install haraka-plugin-resque
# you should disable the default/dummy smtp_forward plugin
sed -i -e 's,^queue/smtp_forward,#queue/smtp_forward,' config/plugins
# this enable resque, if it's not already in config/plugins folder
grep -qxF 'resque' config/plugins || echo "resque" >> config/pluginsNext, copy and edit the default configuration.
cp node_modules/haraka-plugin-resque/config/resque.json config/resque.json
$EDITOR config/resque.json
# now restart haraka
service haraka restartAnd what is this sends on-behalf-of?
The best method is to set the Reply-To header and play around with the From Name. For example, if we set the From Name as reply-to@your-client.com (original/client's from email) <-, then Outlook 365 would look like so reply-to@your-client.com <- <mail-service@your-sending-domain.com>
Then when user hit reply, it will go to/autofill with reply-to@your-client.com; which, if you look at from field, it look exactly like how it work reply-to@your-client.com <- <mail-service@your-sending-domain.com>
Ref: https://stackoverflow.com/questions/2782380/best-practices-sending-email-on-behalf-of-users
To run/debug locally
# run locally with
docker-compose upTo test locally, simply open a new terminal and exec:
# swaks can be install with homebrew on your macos
# type: PLAIN,LOGIN,CRAM-MD5
# note: -tls is important here if you want to test with authenticate
# https://github.com/haraka/Haraka/issues/2760#issuecomment-597248728
swaks -f test@github.com -t resque@github.com \
--server localhost -tls --port 25 --auth LOGIN \
--auth-user "usertest1" --auth-password "testes123"Now you can view/edit the files in data/config and config/resque to manipulate your running container configurations. If you want a completely fresh start/restart, the cleanup.sh script be of help.
# to reset/restart, simply take down the existing docker containers
docker-compose down
# run to cleanup data folder files
./cleanup.sh
# start a new set of containers
docker-compose upNOTE: It is recommended that you enable tls. See Haraka documentation here: https://haraka.github.io/plugins/tls
Since we allow sending with any FROM address, resque requires authentication. Therefore, we must configure resque.json with user credentials. We also need the following configurations for Hakara to work:
- Enable
tlsinconfig/plugins- which is handled inside ofdata/mystart.sh - Because we enable tls, we'll need
tls.ini- which is included indefaults/config/tls.ini - Set your server
HOSTNAMEinside of docker-compose for using OpenSSL generated self-signed cert. - Test it with
-tlswithswaksto confirm thatSTARTTLSis working. If you have SSL issue with certain email client (such as Wordpress SMTP plugin), then you might have to purchase an actual certificate withtls_cert.pemandtls_key.peminside ofdata/configfolder.
Note
- To use self-signed cert with WP Mail SMTP plugin, make sure you disable verification with custom code:
<?php
add_filter('wp_mail_smtp_custom_options', function( $phpmailer ) {
$phpmailer->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
return $phpmailer;
} );Planning / Todo
- Json configuration
- Support login credential
- Support API URL switching based on credentials
- Convert to Typescript and Jest for testing
- More unit testing cases
