在没有电子邮件服务器的情况下测试发送电子邮件 [英] Test sending email without email server
问题描述
我有一个发送电子邮件的Django应用程序。生产服务器具有电子邮件服务器,但我的本地邮箱没有。我希望能够在本地测试电子邮件的发送。有什么办法可以让django不通过电子邮件服务器发送它,而仅将其打印到文件或控制台上?
I have a Django application that sends an email. The production server has an email server but my local box does not. I would like to be able to test sending of email locally. Is there any way that I can have django not send it through the email server and just print out to a file or console?
推荐答案
您可以配置您的应用程序以使用控制台后端来发送电子邮件。
You can configure your application to use the Console Backend for sending e-mail. It writes e-mails to standard out instead of sending them.
更改您的settings.py以包括以下行:
Change your settings.py to include this line:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
别忘了将其删除以进行生产。
Don't forget to remove it for production.
这篇关于在没有电子邮件服务器的情况下测试发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!