Last active
November 5, 2024 14:09
-
-
Save fgsoap/b74c3b436e5c4af6f1bc to your computer and use it in GitHub Desktop.
Auto Reply Emails By Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #-*- coding:UTF-8 -*- | |
| __author__ = nodejx | |
| import imaplib, email, smtplib, time | |
| server = "mail.test.com" | |
| fadd = "[email protected]" | |
| mbody = ["""This is an example!"""] | |
| while True: | |
| i = imaplib.IMAP4(server, 143) | |
| i.login("admin", "passwd") | |
| i.select("INBOX") | |
| types, datas = i.search(None, "NEW") | |
| ids = datas[0] | |
| if ids == "": | |
| i.logout() | |
| pass | |
| else: | |
| for n in ids.split(): | |
| typs, dats = i.fetch(n, '(RFC822)') | |
| for dat in dats: | |
| if isinstance(dat, tuple): | |
| rmsg = email.message_from_string(dat[1]) | |
| msub = rmsg['subject'] | |
| mfro = rmsg['from'].replace("<", '').replace(">",'').split()[-1] | |
| if (mfro == "[email protected]") or (mfro == "[email protected]"): | |
| pass | |
| else: | |
| mhead = ['From:%s' % fadd, 'To:%s' % mfrom ,'Subject:%s' % msub] | |
| smsg = "\r\n\r\n".join(['\r\n'.join(mhead), '\r\n'.join(mbody)]) | |
| s = smtplib.SMTP() | |
| s.connect(server) | |
| s.starttls() | |
| s.login("admin", "passwd") | |
| s.sendmail(fadd, mfro, smsg) | |
| print "Send to %s success!" % mfro | |
| s.quit() | |
| time.sleep(120) |
Author
how to execute ???
python auto_reply_mail.py
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to execute ???