In PHP, you can only send mail using the simple mail () command on systems other than Windows. They expect that a local MTA, such as Postfix, will be installed and configured correctly, as it should be on most web servers. If you want to depend on a third-party or decentralized mail service depends on how critical your application is. A serious dependence on fast and reliable e-mail transmission usually leads to sending mail via SMTP to a central mail server ("big pipe").
However, if you want to have the same function as in PHP, try the following:
import subprocess def send_mail(from_addr, to_addr, subject, body): cmdline = ["/usr/sbin/sendmail", "-f"] cmdline.append(from_addr) cmdline.append(to_addr) mailer = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE) dialog = "From: %s\nTo: %s\nSubject: %s\n\n%s\n.\n" % (from_addr, to_addr, subject, body) return mailer.communicate(dialog)
And use it like: send_mail ("Me < myself@mydomain.com >", "Recip Ient < other@hisdomain.com >", "Teh' Subject", "Mail body")
source share