Skip to content

Instantly share code, notes, and snippets.

@HH0718
Created December 26, 2020 16:09
Show Gist options
  • Save HH0718/6fa22658db1928880af3994682a306d2 to your computer and use it in GitHub Desktop.
Save HH0718/6fa22658db1928880af3994682a306d2 to your computer and use it in GitHub Desktop.
[CREDENTIALS]
EMAIL = "my.email@gmail.com"
PASSWORD = "MySuperSecretPassword"
[SERVER]
SMTP = "smtp.gmail.com"
PORT = 587
import smtplib
from email import encoders
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from vyper import v
v.set_config_name('config')
v.add_config_path('.')
v.read_in_config()
def send_email(recipient, subject):
credentials = v.get('CREDENTIALS')
server = v.get('SERVER')
if not credentials['EMAIL'] and not credentials['PASSWORD']:
print("Missing credentials in config file.")
quit()
server = smtplib.SMTP(server['SMTP'], server['PORT'])
server.starttls()
server.ehlo()
server.login(credentials['EMAIL'], credentials['PASSWORD'])
msg = MIMEMultipart()
msg["From"] = credentials['EMAIL']
msg["To"] = recipient
msg["Subject"] = subject
with open("message.txt", "r") as f:
message = f.read()
msg.attach(MIMEText(message))
filename = "photo.jpg"
attachment = open(filename, "rb")
p = MIMEBase("application", "octet-stream")
p.set_payload(attachment.read())
encoders.encode_base64(p)
p.add_header("Content-Deposition", 'filename')
text = msg.as_string()
server.sendmail(credentials['EMAIL'], recipient, text)
if __name__ == "__main__":
# Change `config.toml.example` to `config.toml` then enter data.
# call send_email() and enter recipient's email and subject as args.
send_email("mubashirhasan2005@outlook.com", "The Subject")
Well I'm making my own gmail client
Regards,
Mohammed Mubashir Hasan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment