Python SMTP bulk Mail

Source: Internet
Author: User

The SMTP module that uses Python is a very simple implementation that has recently encountered working with scripts to handle problems and sending results messages. Today, there is a problem, according to the test results of the script requires mass mail, but the py file to send mail only the first address received the message. A closer look at the interesting places:

The PY for sending mail is as follows:

1 defSendMail (Message,to_addrs)2        ............................3        ...........................4msg =Mimemultipart ()5msg[' from'] =_from6msg[' to'] =To_addrs7        ......................8        ......................9Mailserver.sendmail (_from, To_addrs, message)

Method 1 uses the method is to get to the mail address, "[Email protected],[email protected],[email protected]" as a string as the parameter "To_addrs" to SendMail. After the script runs, only the [email protected] mailbox receives the message, and no subsequent addresses receive the message.

After Google has the Python SMTP, the method of modification is:

Method 2 with ["[email protected]", "[email protected]", "[email protected]"] as a list of parameters "To_addrs" to SendMail.

Then modify the "msg[" to "] = To_addrs" line to "msg[" to "] =", ". Join (To_addrs)", and the accounts in the specified mailing list receive mail

>>> A ="[email protected],[email protected],[email protected]">>>a'[email protected],[email protected],[email protected]'>>>type (a)<type'Str'>>>> B = ["[email protected]","[email protected]","[email protected]"]>>> C =",". Join (b)>>>C'[email protected],[email protected],[email protected]'>>>type (c)<type'Str'>
>>> A = = C
True

The above see A and C no difference, using method 2 successfully done. There is time to continue to look at it, no knowledge is too scary hehe.

Note:

You're using a Gmail mailbox.

Python SMTP bulk Mail

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.