1

I would like to add a newsletter signup to my website which has a backend set up with Django. How should I go about handling email information when submitted to my site? Should I create a new model just for emails? Is there a way I can take emails inputted into my site and have them saved dynamically to my sendgrid account?

I would like to use sendgrid for all of my email campaigns and I would prefer having my data sent there instantly rather than saving in a model table and then manually inputting the contacts into my account.

Mohammed B
  • 305
  • 1
  • 4
  • 14
  • You can store everything directly in SendGrid via the Marketing Campaigns API https://sendgrid.com/docs/API_Reference/Web_API_v3/Marketing_Campaigns/index.html – bwest Dec 13 '16 at 17:35

1 Answers1

1

Just store everything on Sendgrid's servers. Sendgrid has API bindings for Python: pip install sendgrid.

  1. Setup Celery or any other asynchronous task queue to process sign up requests in background. I recommend Celery, it's well supported to play nicely with Django.
  2. Setup a task to handle signups asynchronously:

    # your_app/tasks.py:
    @celery.shared_task
    def newsletter_signup(email, newsletter):
        # use sendgrid API here
        pass
    
    
    # your_app/views.py
    def some_view(request):
        # do what you need, and send a sign up task whenever you want:
        newsletter_signup.delay(request.user.email, 'foobar')
        return HttpResponse('hello, world')
    

Actually, you can use their API directly (without Celery). But in this case request processing will take more time because of the extra time spent on communicating with the API.

Max Malysh
  • 29,384
  • 19
  • 111
  • 115