1#-*- coding: utf-8 -*-
2'''
3傳送txt文字郵件
45'''
6import
smtplib
7from email.mime.text import
mimetext
8 mailto_list=['
***@**.***']
9 mail_host="
smtp.****.com"#
設定伺服器
10 mail_user="
***@**.**"#
使用者名稱11 mail_pass="
********"#
口令 12 mail_postfix="
***.com"#
發件箱的字尾
1314
defsend_mail(to_list,sub,content):
15 me="
hello
"+"<
"+mail_user+"
@"+mail_postfix+"
>
"16 msg = mimetext(content,_subtype='
plain
',_charset='
gb2312
')
17 msg['
subject
'] =sub
18 msg['
from
'] =me
19 msg['
to'] = ";"
.join(to_list)
20try
: 21 server =smtplib.smtp()
22server.connect(mail_host)
23server.login(mail_user,mail_pass)
24server.sendmail(me, to_list, msg.as_string())
25server.close()
26return
true
27except
exception, e:
28print
str(e)
29return
false
30if
__name__ == '
__main__
':
31if send_mail(mailto_list,"
hello
","hello world!
"):
32print
"傳送成功"33
else
: 34
"傳送失敗
"
1#-*- coding: utf-8 -*-
2'''
3傳送html文字郵件
45'''
6import
smtplib
7from email.mime.text import
mimetext
8 mailto_list=["
*****"]
9 mail_host="
smtp.***.com"#
設定伺服器
10 mail_user="
****"#
使用者名稱11 mail_pass="
****"#
口令 12 mail_postfix="
***.com"#
發件箱的字尾
1314
def send_mail(to_list,sub,content): #
to_list:收件人;sub:主題;content:郵件內容
15 me="
hello
"+"<
"+mail_user+"
@"+mail_postfix+"
>"#
這裡的hello可以任意設定,收到信後,將按照設定顯示
16 msg = mimetext(content,_subtype='
html
',_charset='
gb2312
') #
建立乙個例項,這裡設定為html格式郵件
17 msg['
subject
'] = sub #
設定主題
18 msg['
from
'] =me
19 msg['
to'] = ";"
.join(to_list)
20try
: 21 s =smtplib.smtp()
22 s.connect(mail_host) #
連線smtp伺服器
23 s.login(mail_user,mail_pass) #
登陸伺服器
24 s.sendmail(me, to_list, msg.as_string()) #
傳送郵件
25s.close()
26return
true
27except
exception, e:
28print
str(e)
29return
false
30if
__name__ == '
__main__
':
31if send_mail(mailto_list,"
hello
","小五義
"):
32print
"傳送成功
",mailto_list
33else
: 34
"傳送失敗
"
流柯
html傳送郵件 Python傳送郵件(三十)
簡單郵件傳輸協議 smtp 是一種協議,用於在郵件伺服器之間傳送電子郵件和路由電子郵件。python提供smtplib模組,該模組定義了乙個smtp客戶端會話物件,可用於使用smtp或esmtp偵聽器守護程式向任何網際網路機器傳送郵件。這是乙個簡單的語法,用來建立乙個smtp物件,稍後將演示如何用它...
python 傳送郵件
coding utf 8 import smtplib from email.mime.text import mimetext from email.header import header 檔案形式的郵件 def email file mail host smtp.qq.com 郵箱伺服器 ma...
python 傳送郵件
smtp mail transfer protocol 即簡單郵件傳輸協議,它是一組用於由源位址到目的位址傳送郵件的規則,由它來控制信件的中轉方式。python的smtplib提供了一種很方便的途徑傳送電子郵件。它對smtp協議進行了簡單的封裝。直接貼 coding utf 8 import smt...