Search code examples
djangogmail

sending email with gmail smtp


I have this in my setting.py file:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'Pass'

I want to send email to destinations posted from a template:

from django.core.mail.message import EmailMessage
destinations = request.POST['destinations'] #this return string with 2 emails ('[email protected]; [email protected]')
EmailMessage(subject, core, to=[destinations]).send()

it send email just to the first mail and not for others ! is there any action to make this work for all emails posted ?


Solution

  • Pass a list to to:

    import re
    # or you can use request.getlist('destination')
    # I do not know how you generate the two mail addresses
    destinations = re.split(r'[;\s]*', request.POST['destinations'])
    EmailMessage(subject, content, to=destinations)