So this is the email setup:
import ssl
import smtplib
port = 465 # For SSL
smtp_server = "smtp.gmail.com"
sender_email = "[email protected]"
receiver_email = "[email protected]"
password = "password"
message = f"""\
Subject: Email Sent from Blender on MacOS
This Email was sent from Python in Blender on MacOS.
"""
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)
Pretty easy, nothing special. When running this in Python 3.10 on my machine I receive the email and all is good.
But then this error message appears when I run this code as a script in Blenders IDE:
location: <unknown location>:-1
Error: Python: Traceback (most recent call last):
File "/Applications/Blender.app/Contents/Resources/3.1/python/lib/python3.10/smtplib.py", line 1050, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout,
File "/Applications/Blender.app/Contents/Resources/3.1/python/lib/python3.10/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/Applications/Blender.app/Contents/Resources/3.1/python/lib/python3.10/smtplib.py", line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Applications/Blender.app/Contents/Resources/3.1/python/lib/python3.10/smtplib.py", line 1057, in _get_socket
new_socket = self.context.wrap_socket(new_socket,
File "/Applications/Blender.app/Contents/Resources/3.1/python/lib/python3.10/ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "/Applications/Blender.app/Contents/Resources/3.1/python/lib/python3.10/ssl.py", line 1070, in _create
self.do_handshake()
File "/Applications/Blender.app/Contents/Resources/3.1/python/lib/python3.10/ssl.py", line 1341, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
So why is this happening? Well as far as I can tell this is the solution:
On your Mac go to Macintosh HD > Applications > Python3.##
then run the file Install Certificates.command
. And this fixed the issue for me when running a normal Python interpreter using say Pycharm.
As far as I can tell Install Certificates.command
is no where to be found inside the Blender internal Python version. My question is, how do I generate valid SSL certificates inside Blenders Python version without the Install Certificates.command
file?
All I want to do is send emails from Blender. Thank you for reading and for your time!