Skip to content

Instantly share code, notes, and snippets.

@salehi
Forked from frankyxhl/zoho_send_email.py
Created September 5, 2021 07:57
Show Gist options
  • Save salehi/ada0f26fc50b209686f266cac7154cbb to your computer and use it in GitHub Desktop.
Save salehi/ada0f26fc50b209686f266cac7154cbb to your computer and use it in GitHub Desktop.
Python script to send email by zoho.com's mail service
# Code from best solution in page below:
# https://help.zoho.com/portal/community/topic/zoho-mail-servers-reject-python-smtp-module-communications
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.utils import formataddr
# Define to/from
sender = 'sender@example.com'
sender_title = "Allan Smith"
recipient = 'recipient@example.com'
# Create message
msg = MIMEText("Message text", 'plain', 'utf-8')
msg['Subject'] = Header("Sent from python", 'utf-8')
msg['From'] = formataddr((str(Header(sender_title, 'utf-8')), sender))
msg['To'] = recipient
# Create server object with SSL option
server = smtplib.SMTP_SSL('smtp.zoho.com', 465)
# Perform operations via server
server.login('sender@example.com', 'password')
server.sendmail(sender, [recipient], msg.as_string())
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment