Reference link: How does I send mail from a Python script?
Using the SendMail program under Linux to send mail, using the Popen function (Python docs about popen function) can directly invoke Linux system programs, you need to specify the location of the program.
#!/usr/bin/python
#-*-coding:utf-8-*-
#Author: Victor Lv
SENDMAIL = "/usr/sbin/sendmail" #sendmail ( Executable program) is the path
sender = "sender@example.com"
receivers = ["user1@example.com", "user2@example.com"]
Subject = "This is the message header"
Text = "This is the message body. '
#将这些元素组合成一条message message = ' "
\ from
:%s to
:%s
Subject:%s%s" "
% (sender,", ".) Join (receivers), subject, text)
# Send The Mail
import os
p = os.popen ("%s-t-i"% SENDMAIL, "W")
P.W Rite (message)
status = P.close ()
if status:
print "Sendmail exit status", status
Other ways and examples of sending messages in the Python docs:
Email:examples