【发布时间】:2019-04-01 04:16:54
【问题描述】:
我花了几个小时寻找解决方案,但无济于事。我正在尝试在自动生成的电子邮件中包含一些图像,但遇到了一些问题。我不能包含实际的 url,因为 gmail 完全阻止了图像,所以我试图作为附件发送,然后使用 Cids 来引用附件。问题是我还没有找到一种方法来做到这一点。任何帮助都是王牌。
我在 Ubuntu 服务器上使用 Apache2 运行 python 3.6。我曾尝试在 base64 中编码图像,但这根本不起作用。电子邮件中的图像根本没有显示出来。
def createVoucher(email, expiry):
voucherId = str(uuid.uuid4())
email = email
value = 1
expiryDate = expiry
redeemed = 1
connection = mysql.get_db()
cursor = connection.cursor()
cursor.execute("INSERT INTO vouchers (VoucherID, Value, ExpiryDate, Redeemed, Email) VALUES (%s,%s,%s,%s,%s)", (voucherId, value, expiryDate, redeemed, email))
msgBody = render_template('admin/eVoucherEmail.html', voucherId=voucherId, expiry=expiry)
msg = Message('New Sunday Funday eVoucher Received', sender = MAIL_USERNAME, recipients = [email])
msg.html = msgBody
with app.open_resource("static/img/Facebook.jpg") as fp:
msg.attach("Facebook.jpg", "image/jpg", fp.read())
mail.send(msg)
connection.commit()
所以发布的代码可以很好地附加文件,它只是分配一个我可以在我遇到困难的地方使用的内容 ID。
【问题讨论】:
标签: python flask-mail