Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for AWS SES as the SMTP #153

Closed
BhuviTheDataGuy opened this issue Apr 23, 2024 · 25 comments
Closed

Support for AWS SES as the SMTP #153

BhuviTheDataGuy opened this issue Apr 23, 2024 · 25 comments

Comments

@BhuviTheDataGuy
Copy link

We use AWS SES for email.
I have configured the mail server.

SES username and password look like random characters.

But once its configured, I created a new employee, that employee didn't receive any emails. Then manually tried to reset the password. The page kept on loading.

image

@horilla-opensource
Copy link
Owner

Hi @BhuviTheDataGuy ,
Sorry for the inconvenience caused.
Is there any details in the service log?

With Regards,
Team Horilla

@BhuviTheDataGuy
Copy link
Author

No logs on the application side.

I did docker compose logs -f

then navigated to forgot password and tried it. But nothing is displayed on the logs console.

@BhuviTheDataGuy
Copy link
Author

One update:

I did the fresh installation and I just got this error.

(501, b'Invalid MAIL FROM address provided', 'MyCompany HR <AKIA6IRNZXXXXXXXXXXX>')

AKIA6IRNZXXXXXXXXXXX is my SMTP username from AWS SES. And its not in the format of name@domain.com

I think this is the reason its failing.

@horilla-opensource
Copy link
Owner

Hi @BhuviTheDataGuy ,
Thanks for the update.
We'll check with the validations and get back to you.

With Regards,
Team Horilla

@BhuviTheDataGuy
Copy link
Author

This is the only pending part. We are about to go live with Horilla. It would be great if you fix this.

@horilla-opensource
Copy link
Owner

The team is working on this. We'll publish the solution soon.

With Regards,
Team Horilla

@horilla-opensource
Copy link
Owner

Hi @BhuviTheDataGuy ,
Can you make changes in the settings.py file to make adjustments to support for AWS SES email servers for Horilla?
Please check the below link for its configuration.
The easiest way to send emails with Django (using SES from AWS)

Please let us know if you face any issues with this.

With Regards,
Team Horilla

@BhuviTheDataGuy
Copy link
Author

BhuviTheDataGuy commented Apr 25, 2024

Via command line it works, but from Horilla its not.

Steps:

pip install django-ses

vim settings.py
EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_ACCESS_KEY_ID = 'XXXXXXXX'
AWS_SECRET_ACCESS_KEY = 'XXXXXXXX'


python3 manage.py shell
from django.core.mail import send_mail
send_mail(
    'Subject here',
    'Here is the message.',
    'notification@domain.com',
    ['bhuvanesh@domain.com']
)
1

image

@horilla-opensource
Copy link
Owner

Is there any mail server setup from the frontend section?

@BhuviTheDataGuy
Copy link
Author

BhuviTheDataGuy commented Apr 25, 2024

Yes, I have already configured the mail server on the Horilla settings --> Mail server.
But I tried removing that, then it says Primary mail server not found

Also an Off topic - Do you have any slack/discard for supporting?

@horilla-opensource
Copy link
Owner

Okay.
Will add an exemption to that case and commit the solution asap.

With Regards,
Team Horilla

@horilla-opensource
Copy link
Owner

Yes, I have already configured the mail server on the Horilla settings --> Mail server. But I tried removing that, then it says Primary mail server not found

Also an Off topic - Do you have any slack/discard for supporting?

We are planning for starting the support channels in slack. Will share with you the details once started.
Meanwhile for support related queries you can contact at nikhil@cybrosys.in

With Regards,
Team Horilla

@horilla-opensource
Copy link
Owner

Hi @BhuviTheDataGuy ,
Please check the commit [FIX] https://github.com/horilla-opensource/horilla/issues/153[: Support for AWS SES as SMTP](be4b175)

The solution for supporting AWS SES as SMTP is updated in the master.
Please let us know if there is any more issue that you are facing.

With Regards,
Team Horilla

@BhuviTheDataGuy
Copy link
Author

Im not sure, still im getting the same error.

Fresh setup. clone the repo and run the application.
Configured the mail server on the frontend UI

Go to login page, navigate to forgot password --> submit

@horilla-opensource
Copy link
Owner

Currently the AWS SES smtp cannot be setup from the frontend.
Can you please try it out by adding it directly into the settings.py along with the AWS_SES_REGION_NAME and AWS_SES_REGION_ENDPOINT ?

We'll soon publish the frontend UI for configuring the AWS SES smtp servers in Horilla.
Sorry for the inconvenience caused in that.

With Regards,
Team Horilla

@BhuviTheDataGuy
Copy link
Author

BhuviTheDataGuy commented Apr 25, 2024

Tried with the settings.py

But this time the page keeps loading as I posted in 1st image.

EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_DEFAULT_REGION = 'ap-south-1'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
AWS_SES_REGION_ENDPOINT = 'email-smtp.ap-south-1.amazonaws.com'
AWS_ACCESS_KEY_ID = 'XXXXXXX'
AWS_SECRET_ACCESS_KEY = 'XXXXXX'
DEFAULT_FROM_EMAIL = 'notification@xxxxxxxxx.com'

Am I missing something?

@horilla-opensource
Copy link
Owner

horilla-opensource commented Apr 25, 2024

Just to confirm, can you test by adding both the from and to email address in AWS SES identities ?
And add an EMAIL_HOST_USER in the settings.py .

Also make sure there is no email server configured from the frontend.

With Regards,
Team Horilla

@BhuviTheDataGuy
Copy link
Author

BhuviTheDataGuy commented Apr 25, 2024

Same behavior.

No email setup on the front end

DEFAULT_TO_EMAIL = 'user@xxxxx.com'
DEFAULT_FROM_EMAIL = 'notification@xxxxx.com'
EMAIL_HOST_USER = 'AWS ACCESS KEY'

@horilla-opensource
Copy link
Owner

Hi @BhuviTheDataGuy ,
Please add an email address instead of the AWS ACCESS KEY for the EMAIL_HOST_USER.

With Regards,
Team Horilla

@BhuviTheDataGuy
Copy link
Author

I tried that too
I used the email address that is verified in SES

is there any way to enable logging to troubleshoot further?

@BhuviTheDataGuy
Copy link
Author

I tried all these combinations.

EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_DEFAULT_REGION = 'ap-south-1'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
AWS_SES_REGION_ENDPOINT = 'email-smtp.ap-south-1.amazonaws.com'
AWS_ACCESS_KEY_ID = 'xxxxxxxxxxxxxx'
DEFAULT_TO_EMAIL = 'notification@domain.com'
AWS_SECRET_ACCESS_KEY = 'xxxxxxxxxxxxxx'
DEFAULT_FROM_EMAIL = 'HR <notification@domain.com>'
EMAIL_HOST_USER = 'xxxxxxxxxxxxxx'
EMAIL_HOST_PASSWORD = 'xxxxxxxxxxxxxx'
EMAIL_HOST = 'email-smtp.ap-south-1.amazonaws.com'

@horilla-opensource
Copy link
Owner

Hi @BhuviTheDataGuy ,

Can you try only with these values configured in the settings?

EMAIL_BACKEND = "django_ses.SESBackend"
EMAIL_HOST_USER = "name@domain.com"
AWS_SES_REGION_NAME = "ap-south-1"
AWS_SES_REGION_ENDPOINT = "email.ap-south-1.amazonaws.com"
AWS_ACCESS_KEY_ID = "AKIAXXXXXXX"
AWS_SECRET_ACCESS_KEY = "XXXXXXX"

With Regards,
Team Horilla

@BhuviTheDataGuy
Copy link
Author

Im able to make it work, thanks.

But there are some additional steps we need to follow.

AWS SES Credentials can we created in 2 ways.

  1. Create from AWS SES console and this will have only sendemail permission. We can use these credentials for any kind of SMTP workloads. Its a typical SMTP credential only. But the same access keys can't be used for any other purposes.
  2. Create a global user(a normal AWS IAM user) and generate the access keys.

This SES Django module will accept the global credentials or the IAM role attached to the server(EC2). I have removed the access keys and just added the SES sendemail access to the IAM role that is associated with the EC2 instance. Then its resolved.

EMAIL_BACKEND = "django_ses.SESBackend"
EMAIL_HOST_USER = "name@domain.com"
AWS_SES_REGION_NAME = "ap-south-1"
AWS_SES_REGION_ENDPOINT = "email.ap-south-1.amazonaws.com"

@horilla-opensource
Copy link
Owner

horilla-opensource commented Apr 26, 2024

Great.
Glad to hear that. 😍
Will make a doc on the configuration of this also.

With Regards,
Team Horilla

@BhuviTheDataGuy
Copy link
Author

Thanks for your efforts and quick responses here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants