workmail with django rest framework not work

0

I am try to connect my workmail to django for sending mail but it not work. Below is my django setting for my workmail.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.mail.us-east-1.awsapps.com'
EMAIL_PORT = 465 
EMAIL_USE_SSL = True
EMAIL_USE_TLS = False
EMAIL_HOST_USER = 'myemail@domain.com'
EMAIL_HOST_PASSWORD = 'password'

For EMAIL_HOST_USER and EMAIL_HOST_PASSWORD is just for example. but EMAIL_HOST_PASSWORD I use the password for login to workmail, so I don't know it correct or not.

And here is the code for sending mail

from django.core.mail import send_mail
...
send_mail(subject, message, from_email, recipient_list, fail_silently=False)

Please help me to give answer or there is anything for me to try.

asked 9 months ago222 views
1 Answer
0

Hi,

I'm sorry to hear you're experiencing problems with sending mail via Django. What error do you receive?

Kind regards, Robin

AWS
EXPERT
answered 9 months ago
  • I got this error (501, b'5.1.7 Invalid MAIL FROM address provided', 'smtp.mail.us-east-1.awsapps.com') but I think it error because Django can not connect to the workmail with this credential. But I wonder why I write the code in python it work.

  • Hi, I don't think the connection is the problem. Looking at this documentation page the problem is with the email address. Robin

  • Thank you for provide that but as the error 5.1.7 The sender's address was syntactically invalid. but why I write the python code it work with the credential or it may have some bug in django, I'm not sure

    here is the code

    import smtplib
    import ssl
    from email.mime.text import MIMEText
    
    to_email = "tomail@gmail.com"
    from_email = "email@domain.com"
    
    message = "test"
    msg = MIMEText(message, "html")
    msg["Subject"] = "subj"
    msg["To"] = to_email
    msg["From"] = from_email
    
    server = smtplib.SMTP_SSL("smtp.mail.us-east-1.awsapps.com", 465, context=ssl.create_default_context())
    
    server.set_debuglevel(True)
    server.login('email@domain.com', 'password)
    server.send_message(msg)
    server.quit()

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions