Cloudflare has a partnership with MailChannels which has allowed Cloudflare to introduce email sending into its web workers. There is some documentation to set this up but its all over the place. Here are the steps I took to get email sending running, using workers. 2023-10-01T20:12:00.000Z
Cloudflare has a partnership with MailChannels which has allowed Cloudflare to introduce email sending into its web workers. There is some documentation to set this up but its all over the place. Here are the steps I took to get email sending running, using workers.
Before getting started you want to generate public and private keys for your DKIM records. I grabbed steps from this guide -> https://github.com/cloudsecurityalliance/webfinger.io/blob/main/docs.webfinger.io/DKIM-setup.md
Private key as PEM file and base64 encoded txt file:
openssl genrsa 2048 | tee priv_key.pem | openssl rsa -outform der | openssl base64 -A > priv_key.txt
Public key as DNS record:
echo -n "v=DKIM1;p=" > pub_key_record.txt && \
openssl rsa -in priv_key.pem -pubout -outform der | openssl base64 -A >> pub_key_record.txt
SPF record:TXT
, YOUR DOMAIN.COM
, v=spf1 ~all
DMARC record:TYT
,
_dmark
,
v=DMARC1; p=none;rua=mailto:[email protected]
Mail Channels Record:
Important note, this is the domain of your worer sending emails. Its probably something like "dev.yourdomain.com" check your worker setup.
TXT
,_mailchannels
,v=mc1 cfid=YOUR DOMAIN.COM
Mailchannels Domain Key Record:
TXT
,mailchannels._domainkey
,CONTENTS OF pub_key_record.txt
Go into cloudflare and setup a new worker.js and paste in the following code.
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
let respContent = "";
// only send the mail on "POST", to avoid spiders, etc.
if( request.method == "POST" ) {
const formData = await request.formData();
const body = {};
for (const entry of formData.entries()) {
body[entry[0]] = entry[1];
}
fls = JSON.parse(JSON.stringify(body));
let send_request = new Request("https://api.mailchannels.net/tx/v1/send", {
"method": "POST",
"headers": {
"content-type": "application/json",
},
"body": JSON.stringify({
"personalizations": [
{ "to": [ {"email": "[email protected]",
"name": 'Email Tester'}],
"dkim_domain": 'YOURDOMAIN.com',
"dkim_selector": 'mailchannels',
"dkim_private_key": `<${PrivateKey}>`,
}
],
"from": {
"email": "[email protected]",
"name": "admin",
},
"reply_to": {
"email": `${body.email}`,
"name": `${body.name || 'No Name Provided'}`,
},
"subject": `${body.subject || 'No Subject'}`,
"content": [{
"type": "text/plain",
"value":
`Email: ${body.email}
Name: ${body.name || 'No Name Provided'}
${body.message || 'No Message'}
`,
}],
}),
});
const resp = await fetch(send_request);
respContent = resp.status + " " + resp.statusText
}
let htmlContent = "<html><head></head><body><pre>" +
`
<form method="post">
Sub: <input type="text" name="subject" value="Testing email sending" /><br>
Name: <input type="text" name="name" value="Testman Testerguy" /><br>
Email: <input type="text" name="email" value="[email protected]" /><br>
Msg: <input type="text" name="message" value="This is a test email to test the email send worker" /><br>
<input type="submit" value="Send"/>
</form>
` +
"<pre>" + respContent + "</pre>" +
"</body></html>";
return new Response(htmlContent, {
headers: { "content-type": "text/html" },
})
}
This code is crap and extremely insecure. Its a combination of code from various sources. Its super crappy. Its just a simple foundation to get your own worker set up.
Pay close attention to the status messages after posting the form.
Best of luck getting everything running.
Sources:
Other Projects
Tired of showing the contents of your audio books library in your music app?
Creating a working ergonomic keyboard. From files to physical.
Trying to build your own keyboard? Here are some links!
How I created, encrypted note taking application, solid scribe.
If an image is being displayed on a website and for some reason that asset disappears, you can catch that error and display a placeholder image with a little inline js.
Sometimes you need to change the remote origin in a git repo, if the server moves or if you just get better at NGINX and change the URL to something cleaner. Here are the simple steps on how to update your remote origin.
This will walk you through installing a custom rom on your phone, updating the firmware and installing google apps. Then rooting your phone.
Designing and building of Ravenwulfconsulting.com
As we fumble around life, doing little projects we end up learning little things and forgetting a lot of things.
To kill all instances of an application us the command killall
Search text files in current directory and all sub directories. Its super fast so don't worry if you have a node_modules directory or something.
I was noticing high CPU usage for the pipewire process on Ubunutu.
Why would anyone in their right mind us vim? I asked myself this question 543 times in the last 3 years. To my own surprise, I found myself wanting to use vim. The justification being that you can write code without using a mouse.
Sunshine is a desktop streaming client for linux that offers efficient, low latency PC streaming, for free. Download Sunshine onto your linux machine (the host) Sunshine Github Download moonlight onto whatever device you streaming on (the client) Moonlight Homepage
At some point I became infatuated with the SAMA IM01 Case. At only 22 liters, it can house an ATX power supply and a large cooler. I bought two! Thus began the journey of rebuilding both my PC and my unRaid server into smaller cases.
A few highlights of my time programming
Running a bash script on system start can be an involved process, depending on you distro. The proper way is to create a system service and plug it into /init.d but you can leverage the crontab if you want a simple quick way to run something on startup.
Cloudflare has a partnership with MailChannels which has allowed Cloudflare to introduce email sending into its web workers. There is some documentation to set this up but its all over the place. Here are the steps I took to get email sending running, using workers.
You can setup nginx to point subdomains at specific ports.
Sleep Linux Mint with this keyboard shortcut
If your server has a .env file, it may be necessary to parse those variables into a bash script. This can be accomplished by using the 'source' command.
Ergonomic keyboards have a number of benefits.
There is a program called Howdy, which is like Windows Hello. It uses face data as authentication. Howdy Github Repository