I am having a mail service code which was working fine but now throwing Error:
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)
This particular error comes in the robocorp cloud platform but works fine when I run it in the local machine.
Hello, Arunav! What server are you using for email? Is it some well-known one (ex: Gmail, Outlook) or is it a private server you or your company have set up? If the second option, that might explain the reason. The certificate might not be installed properly on your server or it might be a self-signed one that’s installed on your local machine and trusted, but it won’t be installed on the cloud platform.
Thanks for your reply, Arunav! I’ve just tested the Gmail example (How to work with email using Gmail and RPA Framework) on Cloud Platform and it worked correctly for me. Can you please check with the example or adapt your robot to look like the example? If it still doesn’t work, can you share your tasks.robot file with us (replacing the password, of course)? Also, please make sure you used the App password instructions for Gmail (Sign in with App Passwords - Gmail Help) recently Google changed this and only App passwords work.
I am using the python template and the bot is actually dependent on many other functions as well. I can share you the mail function that is throwing this particular error.
Thanks for this, Arunav! The problem is with the code. Sending emails in Python can be pretty tricky and specially if you want to create a SSL context as well. We recommend using the RPA Library for this. Here is an example of the function you sent that will work both locally and on Cloud Platform:
from RPA.Email.ImapSmtp import ImapSmtp
def send_message():
gmail_account = "SENDER_EMAIL"
gmail_password = "PASSWORD_HERE"
recipient = "RECIPIENT_EMAIL"
try:
mail = ImapSmtp(smtp_server="smtp.gmail.com", smtp_port=587)
mail.authorize(account=gmail_account, password=gmail_password)
mail.send_message(
sender=gmail_account,
recipients=recipient,
subject="Message from RPA Python",
body="RPA Python message body",
)
except Exception as e:
print("Error:",str(e))
if __name__ == "__main__":
send_message()
Thank you for the code snippet. Tried this code but received
Error: Connection unexpectedly closed
I am just not sure, actually the send mail function I am using works fine for another process but for this process it is throwing the ssl error.
Like if I elaborate. I have two process.
Read data → Send mail
Insert data → Send mail
Read data, Insert data are two robots assigned in different processes. Both of them are calling the same Send mail function. For one process it is running fine… but for the other one it is giving the ssl error. Therefore I am confused about this.
Thanks for the response, Arunav! Did you get the error in cloud platform or locally? If locally, could you please try it in the cloud platform?
The second thing is really strange . I would suggest to try with my code snippet and if it’s still not working, please open a Zendesk ticket so that we can analyse with full logs. Thank you!