I want to use EmailMultiAlternatives to send emails from my Django project, so have set up a little method:
EMAIL_HOST = ‘***********************************’
EMAIL_USE_TLS = True
EMAIL_HOST_USER = ‘**************************’
EMAIL_PORT = 25
ACCOUNT_EMAIL_VERIFICATION = ‘none’
EMAIL_USE_SSL = False
from django.core.mail import EmailMultiAlternatives
from smtplib import SMTPException
def email(subject, text_content, html_content):
msg = EmailMultiAlternatives(
subject,
text_content,
EMAIL_HOST_USER,
[“******************************”],
)
msg.attach_alternative(html_content, “text/html”)
try:
print(msg.send(fail_silently=False))
print(“Email sent to”)
except SMTPException as e:
print("Email failed")
print(e)
When I go into the shell, it reports one email sent; no error. But the email never arrives.
What makes this so mysterious is that I have a fork of the same project on the same drive on my computer. In that project, it works. I have two command prompts open in the respective folders. I fire up the shell, import the file, call the method. One works and one does not. The code is identical, I copy-and-pasted from one to the other.
Can anyone suggest a reason why one works and the other does not?