Haraka plugin that act as a queue and perform REST post to a remote url.
You're a SASS Provider (such as form submission like Wufoo) requiring to send email on-behalf-of client.
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/plugins
Next, 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 restart
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 [email protected] (original/client's from email) <-
, then Outlook 365 would look like so [email protected] <- <[email protected]>
Then when user hit reply, it will go to/autofill with [email protected]
; which, if you look at from field, it look exactly like how it work [email protected] <- <[email protected]>
Ref: https://stackoverflow.com/questions/2782380/best-practices-sending-email-on-behalf-of-users
# run locally with
docker-compose up
To 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 [email protected] -t [email protected] \
--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 up
NOTE: 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
tls
inconfig/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
HOSTNAME
inside of docker-compose for using OpenSSL generated self-signed cert. - Test it with
-tls
withswaks
to confirm thatSTARTTLS
is 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.pem
andtls_key.pem
inside ofdata/config
folder.
- To use self-signed cert with WP Mail SMTP plugin, make sure you disable verification with custom code:
<?php
// inject this php custom code into your wordpress
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;
} );
- Obviously, this is similar if you manually send with PHPMailer in your PHP application.
// Create a new PHPMailer instance and init ssl option
$mail = new PHPMailer();
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
// In Laravel, set 'config/mail.php' like so
'mailers' => [
'smtp' => [
'transport' => 'smtp',
//... haraka server settings
'stream' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
],
],
],
]
- Json configuration
- Support login credential
- Support API URL switching based on credentials
- More unit testing cases