Posts Tagged email

I’m changing how I deal with spam

SpamMy email address, pupeno@pupeno.com, existed since around 1998 and was never obfuscated or protected in any way. Spam wasn’t such a huge problem in those days. Today my Spam folder has 3200 mails.

My spam filter is quite good, but I still like going through my spam in case some non-spam message was thrown in there. I’ve tried cleaning it weekly, daily, whenever I have free time and even inbox zero. It’s a hassle and I’m tired of it.

My new way to deal with spam is ignoring it. Since my spam is deleted automatically whenever it is more than 30 days old, filling up my inbox won’t be my problem; and whenever I someone tells me “I’ve sent you an email, haven’t you receive it?” I’ll be able to search for it and find it if it was on the spam folder unless it’s more than 30 days old. The cases I won’t be able to spot are mails that just went there. Life is tough.

, , , ,

1 Comment

Printing emails in Django

When developing applications in Django, it may be nice to print emails instead of sending them. If you send them you have to be careful which addresses you use. Just being on the safe side and always using @example.{com,org,net} is not enough, you have to use an address you can actually retrieve emails for. And you have to configure your development environment to actually deliver mails. And then wait for the whole thing in each code-try iteration.

So, basing myself on the testing code, I’ve added this to settings.py and mails are now printed:

if DEBUG:
 from utils import BogusSMTPConnection
 from django.core import mail
 mail.SMTPConnection = BogusSMTPConnection

Of course you’ll also need the BogusSMTPConnection class, I’ve defined it as following:

from textwrap import wrap
class BogusSMTPConnection(object):
  """Instead of sending emails, print them to the console."""
 
  def __init__(*args, **kwargs):
    print("Initialized bogus SMTP connection")
 
  def open(self):
    print("Open bogus SMTP connection")
 
  def close(self):
    print("Close bogus SMTP connection")
 
  def send_messages(self, messages):
    print("Sending through bogus SMTP connection:")
    for message in messages:
      print("tFrom: %s" % message.from_email)
      print("tTo: %s" % ", ".join(message.to))
      print("tSubject: %s" % message.subject)
      print("t%s" % "nt".join(wrap(message.body)))
      print(messages)
      return len(messages)

And that’s it.

, , ,

3 Comments