Skip to content

Instantly share code, notes, and snippets.

@frankyxhl
Last active March 24, 2024 23:45
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save frankyxhl/981055b2f1f1698f873dc8e1956d43db to your computer and use it in GitHub Desktop.
Save frankyxhl/981055b2f1f1698f873dc8e1956d43db 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
# Change below smtp.zoho.com, corresponds to your location in the world.
# For instance smtp.zoho.eu if you are in Europe or smtp.zoho.in if you are in India.
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()
@stanislavn
Copy link

Thanks, really helped me

@sid86-dev
Copy link

It's showing authentication failed

@adityak74
Copy link

Thanks, it worked for me!

@ALEXDINO7
Copy link

Perfect its working

@medkadmiri
Copy link

Authentication Failed

@shohagcsediu
Copy link

it works, thank you

@SasidharanNachimuthu
Copy link

it shows authentication failed how to resolve that

@nhatcher
Copy link

it shows authentication failed how to resolve that

Check that smtp.zoho.com, corresponds to your location in the world. For instance smtp.zoho.eu if you are in Europe or smtp.zoho.in if you are in India. Good luck!

@frankyxhl
Copy link
Author

Check that smtp.zoho.com, corresponds to your location in the world. For instance smtp.zoho.eu if you are in Europe or smtp.zoho.in if you are in India. Good luck!

Thank you very much @nhatcher !
Improved the gist as per your comment.

@dfndo
Copy link

dfndo commented Jul 26, 2023

Any idea how we would send emails but to include our signature also. I believe we would have to use MIMIMultipart incorporating html code?

@piotrw777
Copy link

Great, this was really helpfull!

@tanmayMishra17
Copy link

Awesome this was so cool. Thanks

@rishi23root
Copy link

it shows authentication failed how to resolve that

Check that smtp.zoho.com, corresponds to your location in the world. For instance smtp.zoho.eu if you are in Europe or smtp.zoho.in if you are in India. Good luck!

thanks, it works now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment