Re: sending emails to multiple people

2008-11-19 Thread Rajesh Dhawan

Hi,

> I am trying to send an email to three people as follows:
>
> if request.session['Email'] != '':
> #initialize email variables
> # render both html and text strings from the templates below
> textmessage = render_to_string('email_text.html',
> context_instance=RequestContext(request))
> htmlmessage = render_to_string('email_html.html',
> context_instance=RequestContext(request))
>
> from_email='[EMAIL PROTECTED]'
> to_email=request.session['Email'] +
> ",[EMAIL PROTECTED],[EMAIL PROTECTED]"

That doesn't work because, you are just creating a concatenated string
with those address. Instead, use a list:

to_email = [request.session['Email'], '[EMAIL PROTECTED]',
'[EMAIL PROTECTED]']

> subject = 'Thank you from XXX'
>
> if request.session['EmailFormat'] == 'T':
> #send text email here.
> send_mail(subject,textmessage,from_email,[to_email])

If to_email is already a list as I mentioned above, remove the []
around it here. So the above line becomes:

send_mail(subject,textmessage,from_email, to_email)

>
> if request.session['EmailFormat'] == 'H':
> #send the html email now
> msg = EmailMultiAlternatives(subject,textmessage,
> from_email, [to_email])

Do the same here...

-Rajesh D

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



sending emails to multiple people

2008-11-19 Thread Bobby Roberts

I am trying to send an email to three people as follows:

if request.session['Email'] != '':
#initialize email variables
# render both html and text strings from the templates below
textmessage = render_to_string('email_text.html',
context_instance=RequestContext(request))
htmlmessage = render_to_string('email_html.html',
context_instance=RequestContext(request))

from_email='[EMAIL PROTECTED]'
to_email=request.session['Email'] +
",[EMAIL PROTECTED],[EMAIL PROTECTED]"
subject = 'Thank you from XXX'

if request.session['EmailFormat'] == 'T':
#send text email here.
send_mail(subject,textmessage,from_email,[to_email])

if request.session['EmailFormat'] == 'H':
#send the html email now
msg = EmailMultiAlternatives(subject,textmessage,
from_email, [to_email])
msg.attach_alternative(htmlmessage, "text/html")
msg.send()



The first person gets the email but not the other two.  Where am i
screwing up?  Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---