Simple example that works on Mac or windows (assuming you have a smtp relay setup on windows so you can use localhost as your outgoing smtp server; notice no authentication is needed unless you configure it that way). Keep in mind this is not very robust, only an example.
mailx was a little broken out of the box on Mountain Lion. To fix on Mountain Lion
sudo mkdir -p /Library/Server/Mail/Data/spool
sudo /usr/sbin/postfix set-permissions
[pre=#000000]import platform
def send_mail_windows(receiver,* subject*,* body*,* sender*,* server*):
import smtplib
from email.mime.text import MIMEText
msg = MIMEText(body)
msg’to’] = receiver
msg’from’] = sender
msg’subject’] = subject
smtpObj = smtplib.SMTP(server)
smtpObj.sendmail(sender, receiver], msg.as_string())
smtpObj.quit()
def send_mail_mac(receiver,* subject*,* body*):
import subprocess
cmd = “”“echo “%s” | mailx -s “%s” %s”"" % (body, subject, receiver)
p = subprocess.Popen(cmd, shell=True,* stdout*=subprocess.PIPE)
output, errors = p.communicate()
if errors != None:
print errors
if output:
print output
system = platform.system()
if system == “Darwin”:
send_mail_mac(
‘me@gmail.com’,
‘Mail Time’,
“Look mom, I am sending an email!”
)
elif system == “Windows”:
send_mail_windows(
‘me@gmail.com’,
‘Mail Time’,
“Look mom, I am sending an email!”,
‘noreply@CaptainLaserFace.com’,
‘localhost’
)
else:
# Do some linux stuff, probably use mailx
pass[/pre]