Python Forum
SMTPSenderRefused: (530, b'5.7.0 Must issue a STARTTLS command first
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SMTPSenderRefused: (530, b'5.7.0 Must issue a STARTTLS command first
#1
I'm trying to creating the User Authentication API using FastAPI. My scope is when a new user gets registered via endpoint an email will be sent to verify the JWT token and after verification user will be added to the database. Issue I'm facing to reach to the end is this
Error:
smtplib.SMTPSenderRefused: (530, b'5.7.0 Must issue a STARTTLS command first
whenever control reach to Mailer func API crashed.I tried enabling TLS in my config file but no luck so far.

Here is my config:

EMAIL_HOST_USER ='[email protected]'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_PASSWORD = 'my_password'
EMAIL_USE_TLS = True

Mailer:

from smtplib import SMTP
import smtplib
from email.message import EmailMessage
from core.config import Settings

settings = Settings()


class Mailer:
    @staticmethod
    def send_message(content: str, subject: str, mail_to: str):
        message = EmailMessage()
        message.set_content(content)
        message['Subject'] = subject
        message['From'] = settings.EMAIL_HOST_USER
        message['To'] = mail_to
        SMTP(settings.EMAIL_HOST).send_message(message)



    @staticmethod
    def send_confirmation_message(token: str, mail_to: str):
        confirmation_url = f'localhost:8000/registration/verify/{token}'
        message = '''Hi!
    Please confirm your registration: {}.'''.format(confirmation_url)
        Mailer.send_message(
            message,
            'Please confirm your registration',
            mail_to
        )
Error:
INFO: 127.0.0.1:63757 - "POST /registration/?username=string&email=string%40string.com&password=srinf12 HTTP/1.1" 500 Internal Server Error 2021-07-13 22:54:04,745 INFO sqlalchemy.engine.Engine ROLLBACK ERROR: Exception in ASGI application Traceback (most recent call last): File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 369, in run_asgi result = await app(self.scope, self.receive, self.send) File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 59, in __call__ return await self.app(scope, receive, send) File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\fastapi\applications.py", line 199, in __call__ await super().__call__(scope, receive, send) File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\starlette\applications.py", line 112, in __call__ await self.middleware_stack(scope, receive, send) File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__ raise exc from None File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__ await self.app(scope, receive, _send) File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\starlette\exceptions.py", line 82, in __call__ raise exc from None File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\starlette\exceptions.py", line 71, in __call__ await self.app(scope, receive, sender) File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\starlette\routing.py", line 580, in __call__ await route.handle(scope, receive, send) File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\starlette\routing.py", line 241, in handle await self.app(scope, receive, send) File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\starlette\routing.py", line 52, in app response = await func(request) File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\fastapi\routing.py", line 216, in app raw_response = await run_endpoint_function( File "c:\users\xone\desktop\fastapi-job-board\job_board\lib\site-packages\fastapi\routing.py", line 149, in run_endpoint_function return await dependant.call(**values) File ".\routes\route_user.py", line 32, in create_user Mailer.send_confirmation_message(confirmation["token"], form_data.email) File ".\core\mailer.py", line 26, in send_confirmation_message Mailer.send_message( File ".\core\mailer.py", line 17, in send_message SMTP(settings.EMAIL_HOST).send_message(message) File "C:\Python\Python38\lib\smtplib.py", line 970, in send_message return self.sendmail(from_addr, to_addrs, flatmsg, mail_options, File "C:\Python\Python38\lib\smtplib.py", line 871, in sendmail raise SMTPSenderRefused(code, resp, from_addr) smtplib.SMTPSenderRefused: (530, b'5.7.0 Must issue a STARTTLS command first. r18sm11961741wrt.96 - gsmtp', '[email protected]')
What is going wrong why I am getting this error?How to resolve it?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Command line argument issue space issue mg24 5 1,323 Oct-26-2022, 11:05 PM
Last Post: Yoriz
  clearcase command issue mdalireza 0 2,146 Jul-24-2019, 11:23 AM
Last Post: mdalireza
  Issue with command line arguments artblinked 2 3,104 Feb-22-2019, 03:04 PM
Last Post: artblinked
  Command Prompt Issue benzenegirl 2 2,569 Oct-25-2018, 03:09 PM
Last Post: The_Raven

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020