Skip to content

Instantly share code, notes, and snippets.

@naimurhasan
Created September 29, 2021 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naimurhasan/10198c8c7bfa1d20248ac269313dca30 to your computer and use it in GitHub Desktop.
Save naimurhasan/10198c8c7bfa1d20248ac269313dca30 to your computer and use it in GitHub Desktop.
smtp email send with mail.py
import smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
import key
port = 587 # For starttls
smtp_server = "send.one.com"
sender_email = "snder@senderserver.com"
receiver_email = "reciver@gmail.com"
password = key.PASSWORD
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = receiver_email
msg['Subject'] = 'SMTP Test'
body = 'Hi there, this message was sent from python.'
msg.attach(MIMEText(body,'plain'))
text = msg.as_string()
print('text', text)
server = smtplib.SMTP(smtp_server,587)
server.starttls()
server.login(sender_email, password)
server.sendmail(sender_email,[receiver_email],text)
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment