Mailman 3 rest api example
Mailman 3 is a popular open-source mailing list manager that provides a REST API for managing mailing lists, subscribers, and messages. Here's an example of how to use the Mailman 3 REST API:
Prerequisites
- Mailman 3 installed and configured on your server
- A mailing list created in Mailman 3
- A REST client (e.g.,
curl
or a programming language like Python)
API Endpoints
The Mailman 3 REST API has several endpoints for managing mailing lists, subscribers, and messages. Here are some examples:
- Get a list of all mailing lists:
GET /lists
- Get a specific mailing list:
GET /lists/{list_name}
- Get a list of subscribers for a mailing list:
GET /lists/{list_name}/members
- Add a subscriber to a mailing list:
POST /lists/{list_name}/members
- Remove a subscriber from a mailing list:
DELETE /lists/{list_name}/members/{subscriber_email}
- Send a message to a mailing list:
POST /lists/{list_name}/messages
Example Requests
Here are some example requests using curl
:
- Get a list of all mailing lists:
curl -X GET http://your-mailman3-server.com/lists
- Get a specific mailing list:
curl -X GET http://your-mailman3-server.com/lists/example-list
- Get a list of subscribers for a mailing list:
curl -X GET http://your-mailman3-server.com/lists/example-list/members
- Add a subscriber to a mailing list:
curl -X POST -H "Content-Type: application/json" -d '{"email": "[email protected]"}' http://your-mailman3-server.com/lists/example-list/members
- Remove a subscriber from a mailing list:
curl -X DELETE http://your-mailman3-server.com/lists/example-list/members/[email protected]
- Send a message to a mailing list:
curl -X POST -H "Content-Type: text/plain" -d "Hello, world!" http://your-mailman3-server.com/lists/example-list/messages
Authentication
By default, the Mailman 3 REST API uses basic authentication. You can set a username and password in the mailman.cfg
file or use a token-based authentication system like OAuth.
Error Handling
The Mailman 3 REST API returns errors in JSON format. You can use the curl
command with the -v
option to view the error response:
curl -X GET http://your-mailman3-server.com/lists/example-list -v
This will display the error response in JSON format, including the error message and HTTP status code.