Tools to Check if Your Server is Spamming

This is just a couple of good tools to find out if your server is allowing spammers to route mail through it. The nice thing about these tools is that you don't have to know how a mail server works to test.

This first one will search a large number of major blacklists to see if your server is listed. Being blacklisted means that a number of sources have identified your server as a source of spam email. If you find yourself on one of these lists, it could be a good indication that your server is sending out spam.

http://www.mxtoolbox.com/blacklists.aspx

You can find out why you are blacklisted by a particular list by checking out their website (which is linked to in the report). Then you can repeal the listing to get your server taken off of the list. If you are listed you should definitely try to get your server off of the list, because being listed could severely reduce the delivery chances of legitimate email generated by your server.

The second tool analyzes your server by trying to connect to it in the same way a spammer would. If it does find an opening, you can have it actually try to send a message through your server, just like a spammer would (this requires you to register to the site). This is a surefire way to know if your server is capable of being abused for spamming. Because if you get the test message in your inbox, that means spammers can do the same thing.

http://www.abuse.net/relay.html

Automagically Convert Text to Hyperlinks

This is a function that will take a block of text and wrap hyperlink tags around anything that it recognizes as a link. It supports email addresses and anything that starts with http://, https:// or www.

It is implemented in Javascript but the regular expression code should be pretty universal.

function automagic_link(str) {
    str = str.replace(/([^@ ]+)(@)([A-Za-z0-9.-]+)/gi, '$1@$3');
    str = str.replace(/((http(s?):\/\/)|(www.))+([A-Za-z0-9./&=#?-~%;]+)/gi, 'http$3://$4$5');

    return str;
}

CSS Cleanup Tool

This is a website that you can use to both format and optimize your css code. It can expand code so you can read and edit it or reduce your code to reduce size and increase performance. When optimizing it can even rewrite commands into the shorthand version, which is particularly nice.

http://www.cleancss.com

Sending Email with Attachments in Python

Here is a function to make sending email a little easier in Python.

import smtplib
import os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders

def send_mail(to, subject, text, from="", files=[], cc=[], bcc=[], server="localhost"):
    assert type(to)==list
    assert type(files)==list
    assert type(cc)==list
    assert type(bcc)==list

    message = MIMEMultipart()
    message['From'] = from
    message['To'] = COMMASPACE.join(to)
    message['Date'] = formatdate(localtime=True)
    message['Subject'] = subject
    message['Cc'] = COMMASPACE.join(cc)

    message.attach(MIMEText(text))

    for f in files:
        part = MIMEBase('application', 'octet-stream')
        part.set_payload(open(f, 'rb').read())
        Encoders.encode_base64(part)
        part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
        message.attach(part)

    addresses = []
    for x in to:
        addresses.append(x)
    for x in cc:
        addresses.append(x)
    for x in bcc:
        addresses.append(x)

    smtp = smtplib.SMTP(server)
    smtp.sendmail(from, addresses, message.as_string())
    smtp.close()

I got most of this code from the link below. I just cleaned it up a bit, re-prioritized the arguments and added support for both carbon copy (Cc) and blind carbon copy (Bcc).

http://snippets.dzone.com/posts/show/2038

newer...