Sending emails with attachment in django

前端 未结 1 1593
小鲜肉
小鲜肉 2020-12-25 12:06

I\'m trying to send email with some images attached in django. Code used is this snippet : http://www.djangosnippets.org/snippets/1063/. Dunno why the attachment part return

1条回答
  •  有刺的猬
    2020-12-25 12:21

    The error traceback you've posted doesn't seem to have anything to do with the actual code - it seems to be some sort of problem with middleware (presumably when rendering the 500 error page).

    However, your error is probably caused by your use of the undefined variable name attach in the calls to mail.attach. You don't have an attach variable - you've called the posted files image1 etc, so you should use those names.

    mail.attach(image1.name, image1.read(), image1.content_type)
    mail.attach(image2.name, image2.read(), image2.content_type)
    mail.attach(image3.name, image3.read(), image3.content_type)
    

    0 讨论(0)
提交回复
热议问题