如何使用谷歌smtp服务器从django发送电子邮件?

时间:2021-11-05 14:31:40

I'm looking at https://docs.djangoproject.com/en/dev/topics/email/

我在看https://docs.djangoproject.com/en/dev/topics/email/

My question is, is there way I can use smtp.google.com without authentication or without having to put my auth information into settings.py or as a parameter in the django.core.mail.send_mail function?

我的问题是,在没有身份验证的情况下,我是否可以使用smtp.google.com,或者不需要将我的auth信息放入设置中。py或作为django.core.mail中的参数。send_mail函数?

At this point I'm looking for best practices for using smtp.google.com on django, I understand there are better solutions such as http://sendgrid.com/

此时,我正在寻找在django上使用smtp.google.com的最佳实践,我知道有更好的解决方案,比如http://sendgrid.com/

2 个解决方案

#1


11  

You cannot use smpt.gmail.com without providing your auth_information i.e your gmail password.

如果不提供auth_information i,就不能使用smpt.gmail.com。你的邮箱密码。

However you can put your auth information in a local_settings.py and do not add this local_settings in version control so no one except you would see this file. Include this local_settings in your settings.py.

但是可以将auth信息放在local_settings中。并且不要在版本控制中添加这个local_settings,这样除了您之外没有人会看到这个文件。在settings.py中包含这个local_settings。

settings.py

settings.py

 ...
 EMAIL_HOST = 'smtp.gmail.com'
 EMAIL_PORT = 587
 EMAIL_USE_TLS = True
 ...
 ...
 from local_settings import *

local_settings.py

local_settings.py

EMAIL_HOST_USER = 'user@gmail.com'
EMAIL_HOST_PASSWORD = 'yourpassword'

#2


9  

try including this in settings.py:

尝试在设置中包含这个。

# Email configuration.

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'user@domain.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'user@domain.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

If you have a web domain provider (like namecheap, godady, etc) you can associate you domain (mycompany.com) with Gmail. For that feature ask help in your domain provider or look info in Internet:

如果您有一个web域提供者(如namecheap、godady等),您可以将您的域(mycompany.com)与Gmail关联起来。对于该特性,请向您的域提供程序或在Internet上查找信息:

Hope it helps, cheers.

希望它帮助,干杯。

#1


11  

You cannot use smpt.gmail.com without providing your auth_information i.e your gmail password.

如果不提供auth_information i,就不能使用smpt.gmail.com。你的邮箱密码。

However you can put your auth information in a local_settings.py and do not add this local_settings in version control so no one except you would see this file. Include this local_settings in your settings.py.

但是可以将auth信息放在local_settings中。并且不要在版本控制中添加这个local_settings,这样除了您之外没有人会看到这个文件。在settings.py中包含这个local_settings。

settings.py

settings.py

 ...
 EMAIL_HOST = 'smtp.gmail.com'
 EMAIL_PORT = 587
 EMAIL_USE_TLS = True
 ...
 ...
 from local_settings import *

local_settings.py

local_settings.py

EMAIL_HOST_USER = 'user@gmail.com'
EMAIL_HOST_PASSWORD = 'yourpassword'

#2


9  

try including this in settings.py:

尝试在设置中包含这个。

# Email configuration.

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'user@domain.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'user@domain.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

If you have a web domain provider (like namecheap, godady, etc) you can associate you domain (mycompany.com) with Gmail. For that feature ask help in your domain provider or look info in Internet:

如果您有一个web域提供者(如namecheap、godady等),您可以将您的域(mycompany.com)与Gmail关联起来。对于该特性,请向您的域提供程序或在Internet上查找信息:

Hope it helps, cheers.

希望它帮助,干杯。