12

I noticed that php just has one quick function to send emails and I'm wondering if I can do that in Python. I know that Python has an email module, but I understand that I need to be running an SMTP server to use that, whereas PHP can use sendmail.

I would preferably like to use Python 3 and any help on this would be much appreciated.

Tom Leese
  • 19,309
  • 12
  • 45
  • 70

1 Answers1

6

this is a full tutorial for sending email in python..it looks like they do have sendmail function too..take a look at

try:
   smtpObj = smtplib.SMTP('localhost')
   smtpObj.sendmail(sender, receivers, message)         
   print "Successfully sent email"
except SMTPException:
   print "Error: unable to send email"
Benny Tjia
  • 4,853
  • 10
  • 39
  • 48
  • 1
    I'll try that, putting the host in the constructor made me think that it needed a server running. – Tom Leese Jun 26 '11 at 18:02
  • 1
    Could you please explain where is the example with unix "sendmail" in the tutorial? In php default option in .ini is using "/usr/sbin/sendmail" as the mail sending program. Are you referring to the same? – Vijay Jan 23 '21 at 04:55