Python mail smtp gui programming, pythonsmtpgui
Write the smtp gui programming in python. Use the 163 mailbox to send emails to the QQ mailbox for testing. If you find that your sending failed, try the following methods:
1. log on to your mailbox on the webpage and check whether smtp is enabled in settings, for example, whether smtp in mailbox 163 is enabled
2. If the password you entered is the authorization password of the remote client set in 163, please use the remote login password to log on to the test
We hope that the above two points will help you test successfully ·
:
1 # *-* coding: UTF-8 *-* 2 import Tkinter as tk 3 from email import encoders 4 from email. header import Header 5 from email. mime. text import MIMEText 6 from email. utils import parseaddr, formataddr 7 import smtplib 8 9 10 11 root = tk. tk () 12 root. geometry ('500x400') 13 root. title ('smtp send') 14 15 # enter the sender's email address 16 fram = tk. frame (root) 17 frameL = tk. frame (fram) 18 tk. label (frameL, text = 'enter your mailbox ',). pack () 19 frameL. pack (side = 'left') 20 21 frameR = tk. frame (fram) 22 sender = tk. stringVar () 23 msgsend = tk. entry (frameR, textvariable = sender ,). pack () 24 sender. set ('example @ 163.com ') 25 frameR. pack (side = 'right') 26 fram. pack () 27 28 29 # Enter your email password 30 fram = tk. frame (root) 31 frameL = tk. frame (fram) 32 tk. label (frameL, text = 'enter your mailbox password ',). pack () 33 frameL. pack (side = 'left') 34 35 frameR = tk. frame (fram) 36 Passwo = tk. stringVar () 37 msgpass = tk. entry (frameR, textvariable = passwo ,). pack () 38 passwo. set ('*****') 39 frameR. pack (side = 'right') 40 fram. pack () 41 42 43 # enter the recipient's email address 44 fram = tk. frame (root) 45 frameL = tk. frame (fram) 46 tk. label (frameL, text = 'Enter the recipient's mailbox ',). pack (side = 'left') 47 frameL. pack (side = 'left') 48 49 frameR = tk. frame (fram) 50 receive = tk. stringVar () 51 msgreveive = tk. entry (frame R, textvariable = receive ,). pack () 52 receive. set ('example @ qq.com ') 53 frameR. pack (side = 'left') 54 fram. pack () 55 56 57 # enter the mail content 58 tk. label (root, text = 'Enter the mail content ',). pack (side = 'left') 59 msgrecv = tk. text (root) 60 msgrecv. pack () 61 62 63 # format data 64 def _ format_addr (s): 65 name, addr = parseaddr (s) 66 return formataddr (\ 67 Header (name, 'utf-8 '). encode (), \ 68 addr. encode ('utf-8') if isinstance (add R, unicode) else addr) 69 70 71 def sendEmail (): 72 # retrieve the sender's email address, logon password, and recipient's email address 73 global sender 74 send = sender. get () 75 global passwo 76 passwd = passwo. get () 77 global receive 78 receive = receive. get (). encode () 79 80 # assign a value to 81 from_addr = send 82 password = passwd 83 to_addr = receive 84 smtp_server = 'smtp .163.com '#163 email server 85 msg2 = msgrecv. get ('0. 0', 'end') 86 87 88 msg = MIMEText (msg2, 'P Lain ', 'utf-8') # Information Content 89 msg ['from'] = _ format_addr (u'python enthusiast <% s>' % from_addr) # sender 90 msg ['to'] = _ format_addr (u '% s' % to_addr) # recipient 91 msg ['subobject'] = Header (U' greetings from SMTP ...... ', 'Utf-8 '). encode () # mail title 92 server = smtplib. SMTP (smtp_server, 25) 93 server. set_debuglevel (1) 94 server. login (from_addr, password) 95 server. sendmail (from_addr, [to_addr], msg. as_string () 96 server. quit () 97 msgrecv. insert ('end', U' \ n sent successfully! ') 98 99 # Delete the entered email information 100 def reset (): 101 msgrecv. delete ('1. 0', 'end') 102 103 104 framButton = tk. frame (root) 105 send = tk. button (framButton, text = 'send', command = sendEmail, bg = 'green '). pack (side = 'left ') 106 reset = tk. button (framButton, text = 'cancel', command = reset ). pack (side = 'left ') 107 quit = tk. button (framButton, text = 'logout ', command = root. quit, bg = 'red '). pack (side = 'right') 108 framButton. pack () 109 110 root. mainloop ()