### models.py: from django.db import models from django.contrib.sites.models import Site class Email(models.Model): """Model to store e-mail addresses linked to from the site.""" email = models.EmailField(unique=True) def __str__(self): return self.email def get_absolute_url(self): return '/email/%s/' % self.id class Admin: pass ### views.py: from django import newforms as forms from django.core.mail import send_mail from django.shortcuts import get_object_or_404, render_to_response from models import Email class EmailForm(forms.Form): name = forms.CharField(max_length=100) email = forms.EmailField('E-mail address') subject = forms.CharField(max_length=100) message = forms.CharField(widget=forms.Textarea()) cc_myself = forms.BooleanField(label='Send a copy of my message to me.', required=False) def email_form(request, email_id): recipient = get_object_or_404(Email, pk=email_id) if request.method == 'POST': newdata = request.POST.copy() form = EmailForm(data=newdata) if form.is_valid(): name = form.cleaned_data['name'] email = form.cleaned_data['email'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] cc_myself = form.cleaned_data['cc_myself'] sender = "%s <%s>" % ( name, email ) send_mail(subject, message, sender, [recipient.email,], fail_silently=False) if cc_myself: cc_subject = "Copy of %s" % subject send_mail(cc_subject, message, sender, [sender,], fail_silently=False) return render_to_response('email_links/thanks.html', { 'email': recipient.email }) else: form = EmailForm() return render_to_response('email_links/email_form.html', { 'form': form, 'email': recipient.email }) ### templatetags/email_extras.py: from django.template import Library from django.contrib.sites.models import Site from email_links.models import Email register = Library() def mask_email(email): """ Mask an email address. Credit to jkocherhans (http://www.djangosnippets.org/snippets/79/) """ name, domain = email.split('@') if len(name) > 5: # show the first 3 characters masked_name = name[:3] else: # just use the 1st character masked_name = name[0] return "%s...@%s" % ( masked_name, domain ) register.filter('mask_email', mask_email) def email_link(email, label=None): """ Returns an e-mail link, with an optional label. Examples: {% email_link email label %} {% email_link email %} """ email_object = Email.objects.get_or_create(email=email)[0] if label is None: label = mask_email(email) return '%s' % ( Site.objects.get_current().domain, email_object.get_absolute_url(), label ) register.simple_tag(email_link) ### templates/email_links/email_form.html: """

Send an e-mail to {{ email|mask_email }}

{{ form }}
""" ### templates/email_links/thanks.html: """

Thanks!!

"""