Python uses SendMail to send mail under Linux __linux

Source: Internet
Author: User
Tags python script

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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.