pip install celery python # settings.py INSTALLED_APPS = [ ... 'django_celery_results', ] CELERY_BROKER_URL = 'redis://localhost:6379/0' CELERY_RESULT_BACKEND = 'django-db' pip install django-celery-ses python # settings.py CELERY_EMAIL_TASK_CONFIG = { 'queue': 'default', 'delivery_mode': 1, # non-persistent (1) or persistent (2) 'rate_limit': '100/m', # 100 emails per minute } python # settings.py AWS_ACCESS_KEY_ID = 'your-access-key-id' AWS_SECRET_ACCESS_KEY = 'your-secret-access-key' AWS_SES_REGION_NAME = 'your-ses-region-name' AWS_SES_REGION_ENDPOINT = 'your-ses-region-endpoint' python # settings.py EMAIL_BACKEND = 'django_celery_ses.backends.CeleryEmailBackend' EMAIL_HOST = 'your-smtp-host' EMAIL_PORT = 587 EMAIL_HOST_USER = 'your-smtp-username' EMAIL_HOST_PASSWORD = 'your-smtp-password' EMAIL_USE_TLS = True DEFAULT_FROM_EMAIL = 'your-email@example.com' python # views.py from django.core.mail import EmailMessage from django_celery_ses.tasks import send_email def send_my_email(): email = EmailMessage( 'Hello', 'Body goes here', 'from@example.com', ['to@example.com'], ['bcc@example.com'], reply_to=['another@example.com'], headers={'Message-ID': 'foo'}, ) send_email.delay(email) celery -A your_project_name worker -l info redis-server


上一篇:
下一篇:
切换中文