Something went wrong. Try again.
A script that lets PDS admins email everyone active on the PDS if they have a valid email set
Something went wrong. Try again.
1.5 kB · 52 lines · Created 9mo ago
JavaScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253//emails everyone active on the PDS if they have an email set in case of notifications of maintenance or issues
//npm install @atcute/client//Make sure you have these env set. Does not share with the other email vars// PDS_MODERATION_EMAIL_SMTP_URL=smtps://blah// PDS_MODERATION_EMAIL_ADDRESS=pds@mypdsimport {Client, simpleFetchHandler} from '@atcute/client';
const YOUR_DID_ON_THE_PDS = "did:plc:";const PDS_ADMIN_PASSWORD = "PDS_ADMIN_PASSWORD"; // Replace with actual passwordconst PDS_HOSTNAME = "selfhosted.social";
const content = 'Can be <html> or plain text'const subject = 'Email subject'
const rpc = new Client({handler: simpleFetchHandler({service: `https://${PDS_HOSTNAME}`})});
let repos = await rpc.get('com.atproto.sync.listRepos', { params: { limit: 1000 }})
if (!repos.ok) { console.error(repos);}
let activeRepos = repos.data.repos.filter(x => x.active);for (let repo of activeRepos) { const response = await fetch(`https://${PDS_HOSTNAME}/xrpc/com.atproto.admin.sendEmail`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Basic ' + btoa(`admin:${PDS_ADMIN_PASSWORD}`) }, body: JSON.stringify({ recipientDid: repo.did, content, subject, senderDid: YOUR_DID_ON_THE_PDS }) });
if (!response.ok) { console.log(response); }
const json = await response.json(); console.log(json);
}