如何将文件从 Django 发送到 Gmail?
How to send a file from Django to Gmail?
有一个 feedback
表单,用户可以在其中编写 text
消息并附加 file
。
此表格通过邮件发送给经理(例如gmail
)。
有什么方法可以使此文件以正常格式(例如 preview
发送)以便您可以 immediately see
或 download
吗?
现在,我只是在消息中发送文件 link。
感谢帮助@dirkgroten
def send_contact_us_notification(file, name: str, email: str, body: str, phone='', nda=False):
try:
file = settings.MEDIA_URL[1:] + str(contact_form.file)
from django.core.mail import EmailMessage
msg = EmailMessage('Subject of the Email', 'Body of the email', 'dinamo.mutu111@gmailcom', ['dimaonlyvit@gmail.com'])
msg.attach_file(file)
msg.send()
except Exception as e:
print(e)
有一个 feedback
表单,用户可以在其中编写 text
消息并附加 file
。
此表格通过邮件发送给经理(例如gmail
)。
有什么方法可以使此文件以正常格式(例如 preview
发送)以便您可以 immediately see
或 download
吗?
现在,我只是在消息中发送文件 link。
感谢帮助@dirkgroten
def send_contact_us_notification(file, name: str, email: str, body: str, phone='', nda=False):
try:
file = settings.MEDIA_URL[1:] + str(contact_form.file)
from django.core.mail import EmailMessage
msg = EmailMessage('Subject of the Email', 'Body of the email', 'dinamo.mutu111@gmailcom', ['dimaonlyvit@gmail.com'])
msg.attach_file(file)
msg.send()
except Exception as e:
print(e)