I am developing an application which has a registration form and I need to make an email verification system.
I tried to do it using Elastic Mail as a server, and the flask-mail library.
Here is how i have set up the flask-mail config method:
def config_mail(self, server, port, use_tls, use_ssl, username, apikey, password): self.app.config['DEBUG'] = True self.app.config['MAIL_SERVER'] = server self.app.config['MAIL_PORT'] = port self.app.config['MAIL_USE_TLS'] = use_tls self.app.config['MAIL_USE_SSL'] = use_ssl self.app.config['MAIL_USERNAME'] = username self.app.config['MAIL_API_KEY'] = apikey self.app.config['MAIL_PASSWORD'] = password self.mail = Mail(self.app)
And here is how i call it:
fsql.config_mail('smtp.elasticemail.com', 2525, False, False, "User Name", // From SMTP"API key", // From API"Password" // From SMTP)
And here is how i send the actual mail:
def send_validation_mail(self, user): auth_mail = Message("Advanced School Email Verification Service", sender="advancedschoolsystemservice@gmail.com", recipients=[user['email']] ) auth_mail.body = "Validation Code Here" fsql.mail.send(auth_mail)
This exact same method of sending mails worked for me with another SMTP server but my account there got susspended. When i try to call send_validation_mail function, i get the following output in the console where I am running the flask development server:
send: 'ehlo localhost.localdomain\r\n'reply: b'250-smtp.elasticemail.com\r\n'reply: b'250-PIPELINING\r\n'reply: b'250-SIZE 20971520\r\n'reply: b'250-8BITMIME\r\n'reply: b'250-AUTH=PLAIN LOGIN CRAM-MD5\r\n'reply: b'250-AUTH PLAIN LOGIN CRAM-MD5\r\n'reply: b'250-STARTTLS\r\n'reply: b'250 OK\r\n'reply: retcode (250); Msg: b'smtp.elasticemail.com\nPIPELINING\nSIZE 20971520\n8BITMIME\nAUTH=PLAIN LOGIN CRAM-MD5\nAUTH PLAIN LOGIN CRAM-MD5\nSTARTTLS\nOK'send: 'AUTH CRAM-MD5\r\n'reply: b'334 PDliODg4MWU0LTZjZDItNGVkNS1iYjkyLWZlZDE5N2NlOTdlNT4=\r\n'reply: retcode (334); Msg: b'PDliODg4MWU0LTZjZDItNGVkNS1iYjkyLWZlZDE5N2NlOTdlNT4='send: 'YWR2YW5jZWRzY2hvb2xzeXN0ZW1zZXJ2aWNlQGdtYWlsLmNvbSBlYjUxN2FiYjkwY2FjYzM3NWFiN2U3N2U0MGRkMWY4Yw==\r\n'reply: b'235 Authentication successful\r\n'reply: retcode (235); Msg: b'Authentication successful'send: 'mail FROM:<advancedschoolsystemservice@gmail.com> size=341\r\n'reply: b'250 OK\r\n'reply: retcode (250); Msg: b'OK'send: 'rcpt TO:<dimitarschool@gmail.com>\r\n'reply: b'250 OK\r\n'reply: retcode (250); Msg: b'OK'send: 'data\r\n'reply: b'354 Begin send data. End with CRLF.CRLF\r\n'reply: retcode (354); Msg: b'Begin send data. End with CRLF.CRLF'data: (354, b'Begin send data. End with CRLF.CRLF')send: b'Content-Type: text/plain; charset="utf-8"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 7bit\r\nSubject: Advanced School Email Verification Service\r\nFrom: advancedschoolsystemservice@gmail.com\r\nTo: dimitarschool@gmail.com\r\nDate: Mon, 20 Apr 2020 19:50:36 +0200\r\nMessage-ID: <158740503623.11616.4810701167508943119@localhost.localdomain>\r\n\r\nhi\r\n.\r\n'reply: b'250 OK 61116c08-660a-4151-0008-7c640ee56e31\r\n'reply: retcode (250); Msg: b'OK 61116c08-660a-4151-0008-7c640ee56e31'data: (250, b'OK 61116c08-660a-4151-0008-7c640ee56e31')send: 'quit\r\n'reply: b'221 Good bye\r\n'reply: retcode (221); Msg: b'Good bye'
Unfortunately I do not have a lot of experience with this kind of stuff so this response is gibberish to me - I do not understand what I need to fix.
Side note: I have tried to play around with the TLS
and SSL
encryption by changing their values from True
to False
but no luck there.