Program for mailing list

Here is a basic program for a mailing list in Python:

mailing_list.py

import csv

class MailingList:
    def __init__(self, filename):
        self.filename = filename
        self.emails = []

    def load_emails(self):
        with open(self.filename, 'r') as csvfile:
            reader = csv.reader(csvfile)
            for row in reader:
                self.emails.append(row[0])

    def add_email(self, email):
        self.emails.append(email)

    def remove_email(self, email):
        if email in self.emails:
            self.emails.remove(email)

    def send_email(self, subject, message):
        for email in self.emails:
            print(f"Sending email to {email}: {subject} - {message}")

    def save_emails(self):
        with open(self.filename, 'w') as csvfile:
            writer = csv.writer(csvfile)
            writer.writerow([email for email in self.emails])

# Example usage:
ml = MailingList('mailing_list.csv')
ml.load_emails()

print("Current emails:")
for email in ml.emails:
    print(email)

ml.add_email('[email protected]')
ml.send_email('Hello', 'This is a test email')

ml.remove_email('[email protected]')

print("Updated emails:")
for email in ml.emails:
    print(email)

ml.save_emails()

This program uses a MailingList class to manage a list of email addresses. The class has the following methods:

The program uses the csv module to read and write the email list to a file. The email list is stored in a list of strings, where each string is an email address.

You can customize this program to fit your specific needs, such as adding error handling or integrating with an email service.

mailing_list.csv

[email protected]
[email protected]
[email protected]

This is an example CSV file that contains the initial email list. You can add or remove email addresses as needed.

Note: This is a basic example and you should consider security and privacy when handling email addresses. You may want to use a more secure method to store and manage your email list.