-
-
Save Teakzieas/a4c0d2f0fde8decdf90cd77679ba337a to your computer and use it in GitHub Desktop.
Python script to send email by zoho.com's mail service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
from email.mime.text import MIMEText | |
from email.header import Header | |
from email.utils import formataddr | |
sender_email = '' | |
sender_password = '' | |
def init(email, password): | |
global sender_email, sender_password | |
sender_email = email | |
sender_password = password | |
print("Sender email and password initialized.") | |
def send_email(sender_title, recipient, subject, message): | |
if not sender_email or not sender_password: | |
print("Error: Sender email and password not initialized.") | |
return | |
# Create message | |
msg = MIMEText(message, 'plain', 'utf-8') | |
msg['Subject'] = Header(subject, 'utf-8') | |
msg['From'] = formataddr((str(Header(sender_title, 'utf-8')), sender_email)) | |
msg['To'] = recipient | |
try: | |
# 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.in', 465) | |
# Perform operations via server | |
server.login(sender_email, sender_password) | |
server.sendmail(sender_email, [recipient], msg.as_string()) | |
server.quit() | |
print("Email sent successfully!") | |
except Exception as e: | |
print('Error sending email:', str(e)) | |
# Example usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import emailSender | |
emailSender.init('[email protected]', 'WnugAra5xgyA') | |
sender_title = "Divyessh Sivakumar" | |
recipient_email = '[email protected]' | |
email_subject = "Meeting Time" | |
email_message = "Hey, what time is the meeting later? Sincerely, Divyessh" | |
emailSender.send(sender_title, recipient_email, email_subject, email_message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment