Automatically send e-mails "Born as Summer Flowers" through Python

Today ajupyter and her sister went out shopping for a day, and they were exhausted. I read a very beautiful poem in the evening, Tagore's "Born Like Summer Flowers". It felt very beautiful. In addition, I learned to use python to automatically send emails a few days ago, and decided to send this poem to my good friends for appreciation. a bit.

1. Poems

The following is a link to all the poems,
such as summer flowers

2. Code implementation

note:

  1. This code can theoretically run after filling in the recipient's mailbox, but since I saved the mail information, which is "Sheng Ru Xia Hua", to the local and then read it, I need to pay attention to this.
  2. In addition, if you need to use your own mailbox to send emails to others, you need to find your own authorization password, which is the code I said in the code.

Matters needing attention I framed in red, and the core framed in white
Insert picture description here

import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

with open(r'C:\Users\LENOVO\Desktop\生如夏花.txt',mode='rt',encoding='utf-8') as f:
    content = f.read()
print(content)
def send_email(content):
    # 1.邮件内容配置
    msg = MIMEText(content, 'html', 'utf-8')
    msg['From'] = formataddr(["你想展示给对方的信息(比如你的姓名)", "[email protected]"])
    msg['Subject'] = "生如夏花"
    msg['from'] = '[email protected]'
    msg['to'] = '收邮件的人的邮箱'
    # 2.发送邮件
    server = smtplib.SMTP_SSL("smtp.126.com")
    server.login("[email protected]", "YPLEPSERUAHSFDVB") #这个码每个人不一样,这是我的网易分配的码
    server.sendmail("[email protected]", "收邮件的人的邮箱", msg.as_string())
    server.quit()
send_email(content)

3. Attention

The mail that may be received is in the trash can (laughs).
Insert picture description here

Finally, I wish you all happiness, good health and all the best in the coming new year.

Writing more and more code, less and less BUG, ​​find your partner as soon as possible! ! ! (Laughing)

Guess you like

Origin blog.csdn.net/qq_49821869/article/details/113777389