Comparison of charges to send one email<\/figcaption><\/figure>\nFollowing code from zeptomail sends the email . For this to work you need to get the user name and password from zeptomail. The body to be modified to have the OTP text included. OTP is generated by the function generateotp.<\/p>\n
\n
\r\nimport smtplib, ssl, random\r\nfrom email.message import EmailMessage\r\nport = 587\r\nsmtp_server = \"\"\r\nusername=\"\"\r\npassword = \"\"\r\nmessage = \"Test email sent successfully.\"\r\nmsg = EmailMessage()\r\nmsg['Subject'] = \"Test Email\"\r\nmsg['From'] = \"\"\r\nmsg['To'] = \"\"\r\nmsg.set_content(message)\r\ntry:\r\n if port == 465:\r\n context = ssl.create_default_context()\r\n with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:\r\n server.login(username, password)\r\n server.send_message(msg)\r\n elif port == 587:\r\n with smtplib.SMTP(smtp_server, port) as server:\r\n server.starttls()\r\n server.login(username, password)\r\n server.send_message(msg)\r\n else:\r\n print (\"use 465 \/ 587 as port value\")\r\n exit()\r\n print (\"successfully sent\")\r\nexcept Exception as e:\r\n print (e)\r\n\r\ndef generateotp(glen = 4):\r\n gchars = '0123456789'\r\n gsl = ''.join(random.choice(gchars) for _ in range(glen))\r\n return gsl\r\n<\/code><\/pre>\n<\/div>\nThe email received in the user inbox is shown below.<\/p>\n