python3 SMTP 發郵件 通過測試完整程式碼
阿新 • • 發佈:2019-01-10
#!/user/bin/env python3 import smtplib from email.mime.text import MIMEText def SendEmail(fromAdd,toAdd,subject,text): _pwd = "****************************" #授權碼 msg = MIMEText(text) msg["Subject"] = subject msg["From"] = fromAdd msg["To"] = toAdd try: s = smtplib.SMTP_SSL("smtp.qq.com", 465) s.login(fromAdd, _pwd) s.sendmail(fromAdd, toAdd, msg.as_string()) s.quit() print ("Success!") except smtplib.SMTPException: print('Falied!') if __name__=='__main__': from_="************@qq.com" #你的郵箱 發件地址 to_ = input('Please input Recipient:') #收件地址 subject = input('Please input title:') #郵件標題 text= input('Please input Content:') #郵件內容 SendEmail(from_,to_,subject,text)