My life is short. I use python. I have been using my work for my internship recently. Because my work involves a large amount of data, and the program runs down to use agents, I may not be able to run it for a month, but I am about to go back to the test for two weeks. As a coder of obsessive-compulsive disorder, I must know what happened to my program !!! So I let my program be successfully executed for a while, but I am a very "lazy" person (in fact, excellent programmers must be "lazy! I am determined to write concise code. If yes, the shorter the better, the better. So I wrote a 160-line py 2048 in a short time ago.) After reading many versions, I am very depressed ~ Finally, after sorting out the ten rows, we will send you!
Import smtplib, refrom email. mime. text import MIMETextdef send (fromail, passwd, tomail, sub, info): msg = MIMEText (info) msg ['subobject'] = sub msg ['from'] = fromail smtp = smtplib. SMTP () p = re. compile (R '. *@(. *) ') cn = p. findall (fromail) [0] smtp. connect (r'smtp. '+ cn) smtp. login (fromail, passwd) smtp. sendmail (fromail, [tomail], msg. as_string () smtp. close ()
When we call it, it is very simple. You can directly give your email address + password, the email address, topic, and content you send, in the smtp section, I used a simple regular expression to avoid the trouble. If it is incorrect, I fixed the smtp writing. connect (r 'smtp .yeah.net ') and so on, you can delete the lines p and cn.
For example
Send ('dengyaolong @ yeah.net ', 'Password', 'aolongdeng @ 126.com', 'use My python', 'send Your mail ')