Sending mail SSL certificate Error

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.


I am using the gmail smtp server

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.

def send_message(self, SMTP_host, SMTP_port, receiver_email, message, subject, cc_mail):
        toaddr = receiver_email
        cc = cc_mail
        #Send message
            ins_message = "To: %s\r\n" %",".join(toaddr) + "CC: %s\r\n" % ",".join(cc)+"Subject: "+subject+"\n\n"+message
            context = ssl.create_default_context()
            toaddrs = toaddr + cc
            with smtplib.SMTP_SSL(SMTP_host, SMTP_port, context=context) as server:
                server.login(self.attachment_mail_user, self.app_password)
                                toaddrs, ins_message)

        except Exception as e:

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"
            mail = ImapSmtp(smtp_server="", smtp_port=587)
            mail.authorize(account=gmail_account, password=gmail_password)
                subject="Message from RPA Python",
                body="RPA Python message body",

        except Exception as e:

if __name__ == "__main__":

Please try this out and let me know if it works :slight_smile:


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.

  1. Read data → Send mail
  2. 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!

1 Like

I tried it in the cloud only… Let me raise the ticket then. Thanks for the help. :smile:

1 Like