I am trying to use django's builtin Email class EmailMessage
to send an email with attachment like below
def send_email(path, from_email, to_list, file_name):
subject = 'Output for csv file %s'%(file_name,)
body = 'Please find the attached output file your csv input file %s'%(file_name,)
message = EmailMessage(subject, body, from_email, to_list)
message.attach_file(path)
message.send()
send_email('/home/user/hello.csv', 'myself@gmail.com', ['client@gmail.com'], 'functional_test')
And my Email settings in settings.py
are
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'actual@myhost.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
So from the above settings the EMAIL_HOST_USER was actual@myhost.com
and when i am calling my send_email
function i am specifying from_email
as myself@gmail.com
.
So when i received the email i am receiving it from actual@myhost.com
instead of myself@gmail.com
even though we specified different from_email
.
Is there anything that i can do to receive the mails with from address as myself@gmail.com
?