email_the_pds.js
1//emails everyone active on the PDS if they have an email set in case of notifications of maintenance or issues
2
3//npm install @atcute/client
4//Make sure you have these env set. Does not share with the other email vars
5// PDS_MODERATION_EMAIL_SMTP_URL=smtps://blah
6// PDS_MODERATION_EMAIL_ADDRESS=pds@mypds
7import {Client, simpleFetchHandler} from '@atcute/client';
8
9const YOUR_DID_ON_THE_PDS = "did:plc:";
10const PDS_ADMIN_PASSWORD = "PDS_ADMIN_PASSWORD"; // Replace with actual password
11const PDS_HOSTNAME = "selfhosted.social";
12
13const content = 'Can be <html> or plain text'
14const subject = 'Email subject'
15
16
17const rpc = new Client({handler: simpleFetchHandler({service: `https://${PDS_HOSTNAME}`})});
18
19let repos = await rpc.get('com.atproto.sync.listRepos', {
20 params: {
21 limit: 1000
22 }
23})
24
25if (!repos.ok) {
26 console.error(repos);
27}
28
29let activeRepos = repos.data.repos.filter(x => x.active);
30for (let repo of activeRepos) {
31 const response = await fetch(`https://${PDS_HOSTNAME}/xrpc/com.atproto.admin.sendEmail`, {
32 method: 'POST',
33 headers: {
34 'Content-Type': 'application/json',
35 'Authorization': 'Basic ' + btoa(`admin:${PDS_ADMIN_PASSWORD}`)
36 },
37 body: JSON.stringify({
38 recipientDid: repo.did,
39 content,
40 subject,
41 senderDid: YOUR_DID_ON_THE_PDS
42 })
43 });
44
45 if (!response.ok) {
46 console.log(response);
47 }
48
49 const json = await response.json();
50 console.log(json);
51
52}