python學習 傳送檔案的554錯誤

2021-10-07 23:46:10 字數 1856 閱讀 8471

解決方法:

傳送的訊息體加入鍵值對:

"from"

:"***x.com"

"to"

:"***x.com"

from smtplib import smtp

from email.header import header

from email.mime.text import mimetext

from email.mime.image import mimeimage

from email.mime.multipart import mimemultipart

import urllib

defmain()

: message = mimemultipart(

) text_content = mimetext(

'附件中帶有資料,請查收'

,'plain'

,'utf-8'

) message[

'subject'

]= header(

'本月資料'

,'utf-8'

) message[

'from']=

'***[email protected]'

message[

'to']=

'***[email protected]'

message.attach(text_content)

with

open

('email_.txt'

,'rb'

)as f:

txt = mimetext(f.read(),

'base64'

,'utf-8'

) txt[

'content-type']=

'text/plain'

txt[

'content-disposition']=

'attachment; filename=email_.txt'

message.attach(txt)

with

open

('email_.xlsx'

,'rb'

)as xf:

xls = mimetext(xf.read(),

'base64'

,'utf-8'

) xls[

'content-type']=

xls[

'content-disposition']=

'attachment; filename=email_.xlsx'

message.attach(xls)

smtper = smtp(

'smtp.126.com'

) smtper.starttls(

) sender =

'***[email protected]'

receiver =

['***[email protected]'

]# ***x: 相應郵箱的客戶端授權碼

smtper.login(sender,

'***x'

) smtper.sendmail(sender, receiver, message.as_string())

smtper.quit(

)print

('傳送成功!'

python怎麼傳送檔案 python

這個程式實現了傳送檔案 資料夾功能,其中詳細功能包括,覆蓋傳送,追加傳送,非同步傳送,剪下傳送,同步傳送,其使用方法如下 第一步 在目標機器上開啟recv file xx.py模組 命令為 python recv py 也可以長期開啟 命令為 nohup python recv x.py 需要開啟埠...

python 傳送郵件學習

import smtplib from email.mime.text import mimetext 傳送文字檔案 from email.utils import formataddr 郵箱位址和口令 sender addr 14 xx qq.com 發件人郵箱 password x 這裡的密碼是...

python 郵件傳送學習

author ouyang test time 2021 1 20 15 01 import smtplib from email.header import header from email.mime.text import mimetext def send mail sender,passw...