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