python傳送郵件 實操記錄 傳送一封普通的郵箱

2021-10-03 05:33:20 字數 2674 閱讀 7046

開通qq郵箱的smtp服務的流程詳情_pyhui的技術部落格-csdn部落格

他說以後會得到一串密碼

# 匯入郵件體相關功能

from email.header import header

from email.mime.multipart import mimemultipart

from email.mime.text import mimetext

# 匯入傳送郵件相關功能

from smtplib import smtp_ssl

import smtplib

# 手動這裡改為密碼

smtp_pwd =

'smtp的密碼'

# 這裡是需要修改的

# 郵件傳送者

sender =

"[email protected]"

# 郵件接收者

receiver =

'[email protected]'

# 郵件主體物件

msg = mimemultipart(

)# 頭部物件

header = header(

"郵件主題str", "utf8"

)msg[

'subject'

]= header

msg[

'from'

]= sender

msg[

'to'

]= header(receiver + "努力的", 'utf8'

)mime_text = mimetext(

"郵件正文str", "plain", "utf8"

)msg.attach(mime_text)

host_server =

'smtp.qq.com'

smtp = smtp_ssl(host_server)

smtp.login(sender, smtp_pwd)

smtp.sendmail(sender, receiver, msg.as_string(

))

# 匯入郵件體相關功能

from email.header import header

from email.mime.multipart import mimemultipart

from email.mime.text import mimetext

# 匯入傳送郵件相關功能

from smtplib import smtp_ssl

import smtplib

# 可作業配置用途

# smtp資訊

host_server =

'smtp.qq.com'

# smtp伺服器位址

smtp_pwd =

'imaijoobbbzbge'

# s密碼2

# 發件人郵箱

sender =

"[email protected]"

# 發件人郵箱

class email:

def __init__(self):

self.smtp = self._login_smtp(

) self.msg = mimemultipart(

) def _login_smtp(self):

smtp = smtp_ssl(host_server)

smtp.login(sender, smtp_pwd)

return smtp

def _send_mail(self, receiver):

self.smtp.sendmail(sender, receiver, self.msg.as_string(

)) self.msg[

'to'

]= header(receiver, 'utf8'

) def _write_message(self, subject_title,content):

header = header(subject_title, "utf8"

) self.msg[

'subject'

]= header

self.msg[

'from'

]= sender

mime_text = mimetext(content, "plain", "utf8"

) self.msg.attach(mime_text)

def send_mail(self,subject_title,content,receiver):

self._write_message(subject_title,content)

self._send_mail(receiver)

if __name__ ==

'__main__'

:# 郵件接收者

receiver =

'[email protected]'

obj = email(

) obj.send_mail(

'用類傳送的','試一試希望可以成功',receiver)

測試的效果

Python3 傳送郵件踩坑記錄

新手學習python3.5,根據教程試一試使用python3.5中的smtplib模組傳送電子郵件。出現多個問題 1 error 無法傳送郵件.case 550,b user has no permission 和 error 無法傳送郵件.case 535,b error authenticati...

python3 6傳送郵件

目的 python3.6傳送郵件 環境 python3.6 pycharm import smtplib from email.mime.text import mimetext from email.header import header 傳送郵箱 sender yuan com 接收郵箱 re...

cmakelists實操記錄

cmake help command set qc include usr include amss set qc include usr include amss core check environment variables if env strequal 可以將其想象成乙個配置檔案 在uni...