Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django send mail from admin panel

I want to send an email to users from django admin panel and store the sent mail in the database too. I have two usertypes: 1.Staff 2. Students. When I select staff and give email, it'll send an email to all the staff who are all having "usertype=staff" in User model and vice versa. I found some difficulties to send the mail from the admin panel. Please some one give me an idea.

models.py

username = models.CharField()
    first_name = models.CharField()
    last_name = models.CharField()
    email = models.EmailField()
    password = models.CharField()
    companyname=models.CharField()
    usertype=models.CharField()
    is_staff = models.BooleanField()
    is_active = models.BooleanField()
    is_superuser = models.BooleanField()
    last_login = models.DateTimeField()
    date_joined = models.DateTimeField()
    groups = models.ManyToManyField()
    user_permissions = models.ManyToManyField()


class newsletter(models.Model):
    USERTYPES = (
        ('staff', 'staff'),
        ('student', 'student'),
    )
    usertype=models.CharField(max_length=50,choices=USERTYPES)
    subject=models.CharField(max_length=100)
    message=models.TextField(blank=True)
    sentdate=models.DateTimeField(auto_now = True)

admin.py

admin.site.register(newsletter)
like image 300
user Avatar asked Jun 18 '13 04:06

user


People also ask

How do I send an email in Django?

Sending Emails with the Django ShellWe import the Django send_mail function. Then we import the settings object which contains all the global settings and the per-site settings (those inside the settings.py file). Finally, we pass all the needed arguments to the send_mail function.

How do I use Django to send an email from Gmail?

send_mail() method is imported from django. The send_mail() method handles the transmission of Emails. There are some important parameters of send_mail(), which we have defined here: subject: Contains the subject part of the Email. message: Contains the Email body.

How do I send a message in Django?

To add a message, call: from django. contrib import messages messages. add_message(request, messages.INFO, 'Hello world.

How do I send an email to multiple recipients in Django?

How to send multiple mass emails django. We need to create a Tuple of messages and send them using send mass mail. In this tutorial, we create a project which sends email using Django. We fill the data in the form and send it using Django Email.


1 Answers

Perhaps an admin action would be suitable.

See also: sending email in Django.

like image 64
stellarchariot Avatar answered Sep 28 '22 10:09

stellarchariot