# Multiple Email Send Issues

**URL:** <https://forum.djangoproject.com/t/multiple-email-send-issues/4086>\
**Category:** Using Django\
**Created:** [August 27, 2020, 6:27pm UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086 "2020-08-27T18:27:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![djangopythoner](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/djangopythoner/32/1640_2.png) [@djangopythoner](https://forum.djangoproject.com/u/djangopythoner)\
**Post date:** [August 27, 2020, 6:27pm UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/1 "2020-08-27T18:27:20Z")

</div>

Hi,

to = ‘to@gmail.com’  
cc = context[testnotification] # == Pick from the custom notification profile model [firstemail@gmail.com](mailto:firstemail@gmail.com),secondemail@gmail.com  
from\_email = request.POST.get(‘fromemail’)  
msg = EmailMultiAlternatives(subject, text\_content,from\_email,[to],[cc])  
msg.attach\_alternative(html\_content, “text/html”)  
msg.send() # Mail send code

**Errors:**

Exception Value: Invalid address; only [firstemail@gmail.com](mailto:firstemail@gmail.com) could be parsed from “[firstemail@gmail.com](mailto:firstemail@gmail.com),secondemail@gmail.com”

I am getting the above error while using in To or CC .

---

<div class="post-metadata">

**Author:** ![Suttonium](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/suttonium/32/1264_2.png) [@Suttonium](https://forum.djangoproject.com/u/Suttonium)\
**Post date:** [August 27, 2020, 6:39pm UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/2 "2020-08-27T18:39:48Z")

</div>

Can you edit your original post by surrounding your code in ```, please? We also may need more information regarding what you’re trying to do so if you can, please post the whole view 🙂

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 27, 2020, 8:25pm UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/3 "2020-08-27T20:25:06Z")

</div>

Your recipient list needs to be a list of email addresses, not a string of comma-separated addresses.  
e.g.

```auto
cc = ['first.email@gmail.com', 'second.email@gmail.com']

```

---

<div class="post-metadata">

**Author:** ![djangopythoner](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/djangopythoner/32/1640_2.png) [@djangopythoner](https://forum.djangoproject.com/u/djangopythoner)\
**Post date:** [August 28, 2020, 7:27am UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/4 "2020-08-28T07:27:12Z")

</div>

Thanks sir, let me try same if any issues let you know.

---

<div class="post-metadata">

**Author:** ![djangopythoner](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/djangopythoner/32/1640_2.png) [@djangopythoner](https://forum.djangoproject.com/u/djangopythoner)\
**Post date:** [August 30, 2020, 7:52am UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/5 "2020-08-30T07:52:10Z")

</div>

Hi Sir,

If I used hardcoded as suggested format it is working fine. But when I take data from the model to send email same errors are coming.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/4/48bcf3bb32dd24a5afb27840a3c78e69b94c727c.png)

Here I am capturing the email id’s.

//Get dynamic values from model based on filter  
leavnotifications = leavenotification.objects.filter(company\_id=context[‘business\_unit\_id’])

```
    for lnotification in leavnotifications:
        context['staffnotification'] = lnotification.staff
        context['workernotification'] = lnotification.worker

```

//End Here\*\*\*\*\*

**Email Send Code:**

subject = 'Request has been approved by ’ + str(request.user.profile.full\_name) + ’ at '+str(formatedDate)  
to = context[‘workernotification’] # Values coming here from profile  
print("To Emai \*\*: "+to)  
from\_email = request.POST.get(‘level3’)  
text\_content = ‘This is an important message.’  
html\_content = '

Hi,  
try:  
msg = EmailMultiAlternatives(subject, text\_content,from\_email,[to])  
msg.attach\_alternative(html\_content, “text/html”)  
msg.send() # Mail send code  
except BadHeaderError:  
return HttpResponse(‘Invalid header found.’)  
Errors:

Exception Value: Invalid address; only [first@gmail.com](mailto:first@gmail.com)’ could be parsed from “[first@gmail.com](mailto:first@gmail.com)’,'second@gmail.com”

---

<div class="post-metadata">

**Author:** ![djangopythoner](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/djangopythoner/32/1640_2.png) [@djangopythoner](https://forum.djangoproject.com/u/djangopythoner)\
**Post date:** [August 30, 2020, 7:52am UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/6 "2020-08-30T07:52:44Z")

</div>

Hi ,

If I used hardcoded as suggested format it is working fine. But when I take data from the model to send email same errors are coming.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/4/48bcf3bb32dd24a5afb27840a3c78e69b94c727c.png)

Here I am capturing the email id’s.

//Get dynamic values from model based on filter  
leavnotifications = leavenotification.objects.filter(company\_id=context[‘business\_unit\_id’])

```
    for lnotification in leavnotifications:
        context['staffnotification'] = lnotification.staff
        context['workernotification'] = lnotification.worker

```

//End Here\*\*\*\*\*

**Email Send Code:**

subject = 'Request has been approved by ’ + str(request.user.profile.full\_name) + ’ at '+str(formatedDate)  
to = context[‘workernotification’] # Values coming here from profile  
print("To Emai \*\*: "+to)  
from\_email = request.POST.get(‘level3’)  
text\_content = ‘This is an important message.’  
html\_content = '

Hi,  
try:  
msg = EmailMultiAlternatives(subject, text\_content,from\_email,[to])  
msg.attach\_alternative(html\_content, “text/html”)  
msg.send() # Mail send code  
except BadHeaderError:  
return HttpResponse(‘Invalid header found.’)  
Errors:

Exception Value: Invalid address; only [first@gmail.com](mailto:first@gmail.com)’ could be parsed from “[first@gmail.com](mailto:first@gmail.com)’,'second@gmail.com”

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 30, 2020, 12:36pm UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/7 "2020-08-30T12:36:02Z")

</div>

I would need to see the **complete** model you’re using to be sure I’m giving you the right advice.

If you’re using a text field, then it is up to you to convert that text into a list.  
If you’re not, then it would also be helpful to see the **complete** view in which you’re trying to do this in addition to seeing the model.

(See the [Python split function](https://docs.python.org/3/library/stdtypes.html#str.split) for some ideas.)

---

<div class="post-metadata">

**Author:** ![djangopythoner](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/djangopythoner/32/1640_2.png) [@djangopythoner](https://forum.djangoproject.com/u/djangopythoner)\
**Post date:** [August 31, 2020, 8:16am UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/8 "2020-08-31T08:16:02Z")

</div>

Hi Sir,

Please find the below model details.

class leavenotification(models.Model):

```
company = models.OneToOneField(business_unit, on_delete=models.DO_NOTHING)

staff=models.TextField(max_length=1000)

worker = models.TextField(max_length=1000)

def __str__ (self):

    return str(self.company)+" - "+str(self.worker)

verbose_name_plural = "Leave Notification"
```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 31, 2020, 11:42am UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/9 "2020-08-31T11:42:09Z")

</div>

So yes, you are using a TextField for this, and so my [advice from above](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/7) applies.

---

<div class="post-metadata">

**Author:** ![djangopythoner](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/djangopythoner/32/1640_2.png) [@djangopythoner](https://forum.djangoproject.com/u/djangopythoner)\
**Post date:** [August 31, 2020, 12:38pm UTC](https://forum.djangoproject.com/t/multiple-email-send-issues/4086/10 "2020-08-31T12:38:58Z")

</div>

Thank you very much sir, now I am using **to.split(",")** and working fine.

Once again thanks to you.
