Tuesday, March 17, 2009

Sending simple email using python

Source http://snippets.dzone.com/posts/show/658

In my case, I can send simple email using smtplib but the I received empty/blank email which is without From/To/Body appeared on my email client (Thunderbird).

So you need to wrap your email with email.MIMEText as sample codes bellow:

import smtplib
from email.MIMEText import MIMEText

def sendTextMail(to,sujet,text,server="localhost"):
fro = "Expediteur "
mail = MIMEText(text)
mail['From'] = fro
mail['Subject'] =sujet
mail['To'] = to
smtp = smtplib.SMTP(server)
smtp.sendmail(fro, [to], mail.as_string())


Warning: mkdir() [function.mkdir]: Permission denied on Fedora

Source http://gallery.menalto.com/node/42302#comment-176477

The problem in my case was that I had the SELinux's security features enabled in my Fedora Core 4 setup. I switched SELinux to permissive mode by editing /etc/sysconfig/selinux -
putting SELINUX=permissive.

There's probably a nicer way than just disabling the security but I was after a simple solution. SELinux FAQ is here.

You need to reboot to make it effective.