0

I think the problem is with the SSL certification.

Please tell me if there is any problem with the code

I'm Using MacOS.Please help me to resolve this problem.

I'm using PyCharm CE Version 2023.1 I tried to change the local certificate and it won't work.Please help me resolve this problem

Code:

from email.message import EmailMessage
from mypassword import password
import ssl
import smtplib

email_sender = 'smdinurakithnada@gmail.com'
email_password = password

email_receiver = 'kayasa4656@wiemei.com'

subject = "Subscribe"
body = """
Don't forget to subscribe
"""

em = EmailMessage()
em['From'] = email_sender
em['To'] = email_receiver
em['Subject'] = subject
em.set_content(body)

context = ssl.create_default_context()
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
    smtp.login(email_sender, email_password)
    smtp.sendmail(email_sender, email_receiver, em.as_string())

Problem:

"/Users/vindhyareyani/Dinura/Dinura/email sender/bin/python" /Users/Shared/Dinura/20 Python Projects/email sender/app.py
Traceback (most recent call last):
File "/Users/Shared/Dinura/20 Python Projects/email sender/app.py", line 23, in \<module\>
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/smtplib.py", line 1050, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout,
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/smtplib.py", line 341, in connect
self.sock = self.\_get_socket(host, port, self.timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/smtplib.py", line 1057, in \_get_socket
new_socket = self.context.wrap_socket(new_socket,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 517, in wrap_socket
return self.sslsocket_class.\_create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1075, in \_create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1346, in do_handshake
self.\_sslobj.do_handshake()
ssl.SSLCertVerificationError: \[SSL: CERTIFICATE_VERIFY_FAILED\] certificate verify failed: unable to get local issuer certificate (\_ssl.c:992)

Process finished with exit code 1
Cow
  • 2,543
  • 4
  • 13
  • 25
  • In short: the trust store used by Python is not properly setup - the duplicate shows how to fix it. Note that it might also be that there is some SSL interception system in your environment which changes the certificate. `openssl s_client -connect smtp.gmail.com:465` will then show a different issuer for the certificate than expected. – Steffen Ullrich Jul 31 '23 at 14:00

0 Answers0