Use My Python, Send Your Mail (10 lines of code)

Source: Internet
Author: User

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 ')





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.