I've signed up in Microsoft live SMTP server and created an email for my django app to send mail from my domain. But the problem is these configurations doesn't work and I can not send email from my django app running on local host to another email address. What's wrong? This is my code:
#Settings.py
# Email Server config
DEFAULT_FROM_EMAIL = 'Hamid FzM <hamidfzm@example.com>'
EMAIL_HOST = 'smtp.live.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'hamidfzm@example.com'
EMAIL_HOST_PASSWORD = 'something'
For testing purpose each time I visit 127.0.0.1/test/
an email will be send to my account by calling this function
#views
def test(request):
from django.core.mail import EmailMessage
EmailMessage('Test', 'This is body', to=['other@example.com'])
I think you need to load those settings properly and run the send on the message object...
# import settings
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
# send an email
from django.core.mail import EmailMessage
message = EmailMessage(subject="Peter Maffay", body="test", from_email="it@maffay.com", to=["peter.maffay@gmail.com"])
message.send(fail_silently=False)
This code fragment works for me
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.