pip install django-celery-ses python EMAIL_BACKEND = 'django_ses.SESBackend' AWS_ACCESS_KEY_ID = 'Your-AWS-Access-Key-ID' AWS_SECRET_ACCESS_KEY = 'Your-Secret-Access-Key' AWS_SES_REGION_ENDPOINT = 'email.us-west-2.amazonaws.com' python from django_ses import SESBackend from celery import shared_task, current_app @shared_task def send_email(subject, message, recipient_list): connection = SESBackend( access_key=current_app.conf.get('AWS_ACCESS_KEY_ID'), secret_key=current_app.conf.get('AWS_SECRET_ACCESS_KEY'), region_name=current_app.conf.get('AWS_SES_REGION_NAME'), region_endpoint=current_app.conf.get('AWS_SES_REGION_ENDPOINT'), ) email = EmailMessage( subject=subject, body=message, from_email='sender@example.com', to=recipient_list, connection=connection ) email.send() python from myapp.tasks import send_email send_email.delay('Hello', 'This is a test email.', ['recipient@example.com'])


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