如何使用 smtp 模块将符号、数字、文本作为段落发送?

how to send symbols , numbers , text as a paragraph with smtp module?

正如您在下面看到的,我有一个使用 smtp 模块将邮件发送回 usr_mail 的脚本,函数 mail_man 接受参数 message 并通过邮件发送,通过我的测试,我向脚本传递了一些简单的消息,但我似乎没有发送传递的消息,而是显示 this message has no body text

一些消息示例:

"hello world !!! :) "

"you got mail from : " + str(usr_mail)

" @ somthing "

如何使用 smtp 模块

发送带有符号数字字母的段落之类的消息
import smtp


def mail_man(message):

    handle = smtplib.SMTP('smtp.gmail.com', 587)
    handle.starttls()
    handle.login(usr_mail , pass_wrd)
    handle.sendmail(usr_mail , usr_mail , message)
    handle.quit()


    print ( " Successfully sent email to :: " +  usr_mail)
    return 



if __name__ == "__main__":
    print (usr_mail , pass_wrd )
    mail_man(message="hello world !!! :) ")

我建议为段落回复创建一个单独的文件,然后从 smtplib 导入 EmailMessage() class,这样您就可以将该消息传递到电子邮件。我会推荐尝试这个:

import smtplib
from email.message import EmailMessage

# Open the plain text file.
txtfile = 'name_of_your_file'
with open(txtfile) as f_obj:
   # Create a blank message and then add the contents of the
   # file to it
   msg = EmailMessage()
   msg.set_content(f_obj.read())

msg['Subject'] = 'your_subject'
msg['From'] = me
msg['To'] = you

# Send the message through your own SMTP server.
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()

这将允许您发送任何类型的长消息,因为它将文件的内容保存为字符串,然后将其添加到文件中,因此没有转换错误。