Drwhite
Drwhite

Reputation: 1685

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 ?

Upvotes: 0

Views: 151

Answers (1)

iMom0
iMom0

Reputation: 12911

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)

Upvotes: 1

Related Questions