#send_mail
#python 傳送郵件的模組
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#匯入smtplib和mimetext
import smtplib
from email.mime.text import mimetext
#############
#要發給誰
#mailto_list=["[email protected],[email protected]"]
#####################
mailto_list=
a=input("請輸入接收人的郵箱")
#設定伺服器,使用者名稱、口令以及郵箱的字尾
mail_host="smtp.163.com" ##請注意,這裡需要你的郵箱服務提供商已經為你開啟了smtp服務 qq 163 or others
mail_user="......" #你的email使用者名稱
mail_pass="......."
mail_postfix="163.com"
######################
def send_mail(to_list,sub,content):
#'''''
#to_list:發給誰
#sub:主題
#content:內容
#send_mail("[email protected]","sub","content")
#'''''
me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = mimetext(content)
msg['subject'] = sub #設定主題
msg['from'] = me #發件人
msg['to'] = ";".join(to_list) #收件人
try:
s = smtplib.smtp()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me, to_list, msg.as_string())
s.close()
return true
except exception as e:
print(str(e))
return false
if __name__ == '__main__':
sendcontent=input("請輸入傳送內容(郵箱**雙引號):")
if send_mail(mailto_list,"hey guys",sendcontent):
print("傳送成功!")
else:
print("傳送失敗!")
python 實現傳送郵件
可採用email模組傳送電子郵件附件。傳送乙個未知mime型別的檔案附件其基本思路如下 1.構造mimemultipart物件做為根容器 2.構造mimetext物件做為郵件顯示內容並附加到根容器 3.構造mimebase物件做為檔案附件內容並附加到根容器 a.讀入檔案內容並格式化 b.設定附件頭 ...
python實現傳送郵件
有時我們需要程式在執行出現問題時傳送郵件通知我們,在這裡寫了乙個使用qq傳送的python指令碼,也是綜合了網上的資源 然而網上的案例好像都不能用 搞得,當然只要把主機埠啥的改一下就能使用其他郵箱了,如下 usr bin python coding utf 8 import smtplib from...
Python實現傳送郵件
coding utf 8 引入相關的模組 import smtplib from email.mime.text import mimetext from email.mime.image import mimeimage from email.header import header from e...