saasforge / open-source-saas-boilerpate

Free SaaS boilerplate (Python/PostgreSQL/ReactJS/Webpack)
https://www.saasforge.dev
MIT License
803 stars 115 forks source link

Email with AWS SES throws "Invalid Mail From address" error #16

Open mjarmijo opened 3 years ago

mjarmijo commented 3 years ago

Hello, I am trying to demo the application, but I cannot get the email registration to work. I am trying to have the app send emails using my AWS SES account, which I can get working in python with the flask_mail module.

from flask import Flask from flask_mail import Message from flask_mail import Mail

app = Flask(name) app.config.update(dict( MAIL_DEBUG = True, MAIL_SERVER = 'email-smtp.us-west-2.amazonaws.com', MAIL_PORT = 587, MAIL_USE_TLS = True, MAIL_USE_SSL = False, MAIL_USERNAME = 'MYUSERNAME', MAIL_PASSWORD = 'MYPASSWORD', ADMIN_EMAIL='hello@mysite.io', MAIL_DEFAULT_SENDER='hello@mysite.io' ))

mail = Mail(app) msg = Message('test subject', sender='hello@mysite.io', recipients=['email@personal.com']) msg.body = 'Yes, it works now."

with app.app_context(): mail.send(msg)

Using the above config and code I can get the email sent to my personal gmail account that I am using to register on the SaaSForge boilerplate Please Register page.

I am using the exact same config for my SasSForge Boilerplate .env file, but when I attempt to create my account on the Please Register page, I get the errors about invalid MAIL FROM posted below.

Note that for SES the username and password are strings that are not a traditional myuser@mysite.com email address - maybe this is related? Again, when i use the regular flask_mail module I don't have any issue and it logs in the same way.

Any idea how to fix this error so I can register and test the app?

127.0.0.1 - - [21/Oct/2020 23:49:39] "GET /auth/finishregister/c9e75c30-81cc-41b6-84fc-673f7b334ffe96e HTTP/1.1" 200 - send: 'ehlo 161.133.158.192.in-addr.arpa\r\n' reply: b'250-email-smtp.amazonaws.com\r\n' reply: b'250-8BITMIME\r\n' reply: b'250-SIZE 1048573360\r\n' reply: b'250-STARTTLS\r\n' reply: b'250-AUTH PLAIN LOGIN\r\n' reply: b'250 Ok\r\n' reply: retcode (250); Msg: b'email-smtp.amazonaws.com#$\nSIZE #$\nSTARTTLS\nAUTH PLAIN LOGIN\nOk' send: 'STARTTLS\r\n' reply: b'220 Ready to start TLS\r\n' reply: retcode (220); Msg: b'Ready to start TLS' send: 'ehlo 161.133.458.192.in-addr.arpa\r\n' reply: b'250-email-smtp.amazonaws.com\r\n' reply: b'250-8BITMIME\r\n' reply: b'250-SIZE 10485760\r\n' reply: b'250-STARTTLS\r\n' reply: b'250-AUTH PLAIN LOGIN\r\n' reply: b'250 Ok\r\n' reply: retcode (250); Msg: b'email-smtp.amazonaws.com\n844BITMIME\nSIZE 10483345760\nSTARTTLS\nAUTH PLAIN LOGIN\nOk' send: 'AUTH PLAIN MYPASSWORD\r\n' reply: b'235 Authentication successful.\r\n' reply: retcode (235); Msg: b'Authentication successful.' send: 'mail FROM: size=2542\r\n' reply: b'501 Invalid MAIL FROM address provided\r\n' reply: retcode (501); Msg: b'Invalid MAIL FROM address provided' send: 'rset\r\n' reply: b'250 Ok\r\n' reply: retcode (250); Msg: b'Ok' send: 'quit\r\n' reply: b'221 Bye\r\n' reply: retcode (221); Msg: b'Bye' Exception in thread Thread-7: Traceback (most recent call last): File "/Users/me/git/open-source-saas-boilerpate/venv/lib/python3.8/site-packages/flask_mail.py", line 188, in send self.host.sendmail(sanitize_address(envelope_from or message.sender), File "/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 871, in sendmail raise SMTPSenderRefused(code, resp, from_addr) smtplib.SMTPSenderRefused: (501, b'Invalid MAIL FROM address provided', '=?utf-8?q?Your_company_name?= MYUSERNAME')

angelhvargas commented 2 years ago

it seems this repo is abandoned as well.