I am trying to use the django send_mail method. I am running into 2 issues, notably converting mail addresses from a list into a csv to be used in the recipients. The second issue is getting the list of user emails from the notifications model.
my models
class notifications(models.Model):
notID = models.AutoField(primary_key=True)
notSubject = models.CharField(max_length=100)
notBody = models.TextField()
notDate = models.DateField(auto_now_add=True)
notRecepients = models.ManyToManyField(UserProfile, related_name='recepients')
notPoster = models.ForeignKey(UserProfile,related_name='notposter')
deleted = models.BooleanField()
def __unicode__(self):
return u'%s ' % ( self.notSubject)
class UserProfile(User):
onames = models.CharField(max_length=30, blank=True)
phoneNumber = models.CharField(max_length=15, blank=True)
regNo = models.CharField(max_length=15)
image = models.ImageField(max_length=100,upload_to='photos/%Y/%m/%d', blank=True, null=True, default='photos/2010/03/placeholder.jpg')
course = models.CharField(max_length=30, blank=True, null=True)
timezone = models.CharField(max_length=50, default='Africa/Nairobi')
smsCom = models.BooleanField()
mailCom = models.BooleanField()
class notifications_sms_mail(models.Model):
notId = models.OneToOneField(notifications)
sms = models.BooleanField()
email = models.BooleanField()
my view
def notif_sms_mail(request):
user = UserProfile.objects.get(pk=request.session['_auth_user_id'])
mailform = notif_sms_mail_Form(request.POST)
if mailform.is_valid():
notid=request.POST['notId']
mailform.save()
notif = notifications.objects.get(deleted='0', notID = notid)
rec = (UserProfile.objects.values('email')).filter(mailCom='1')
mail = notifications_sms_mail.objects.get(email='1', notId=notid)
if notif.notID == mail.notId:
send_mail(notSubject, notBody, 'from ****@gmail.com',rec, fail_silently=False)