from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.management.base import BaseCommand
from django.core.urlresolvers import reverse

from post_office import mail


class Command(BaseCommand):
    help = "Notify users to update."

    def handle(self, *args, **options):
        domain = Site.objects.get_current().domain
        full_url = "https://{}{}".format(domain,
                                         reverse('edit_common_profile'))
        for user in User.objects.filter(common_profile__is_student=True,
                                        is_active=True):
            mail.send([user.email],
                       template="update_common_profile",
                       context={'user': user, 'full_url': full_url})
            self.stdout.write(u'Emailed {}.'.format(user.email))

@@ -82,16 +82,67 @@
 rt Site%0A
+from django.core.exceptions import ValidationError%0A
 from dja
@@ -185,16 +185,16 @@
 Command%0A
-
 from dja
@@ -231,16 +231,17 @@
 everse%0A%0A
+%0A
 from pos
@@ -670,18 +670,57 @@
 ve=True)
-:%0A
+.exclude(email=%22%22):%0A            try:%0A    
         
@@ -747,16 +747,19 @@
 email%5D,%0A
+   
         
@@ -830,16 +830,19 @@
         
+ 
+  
 context=
@@ -879,16 +879,20 @@
 l_url%7D)%0A
+    
         
@@ -948,8 +948,128 @@
 email))%0A
+            except ValidationError:%0A                self.stdout.write(u'Error with %7B%7D'.format(user.email))%0A            %0A

Handle missing and invalid email addresses.