Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- from getpass import getpass
- from email.mime.text import MIMEText
- sender = 'example_sender@gmail.com'
- receiver = 'example_receiver@gmail.com'
- content = """The receiver will see this message.
- Best regards"""
- msg = MIMEText(content)
- msg['From'] = sender
- msg['To'] = receiver
- msg['Subject'] = 'Simple app script'
- with open('/path/to/your/file', 'r') as file:
- content = file.read()
- smtp_server_name = 'smtp.gmail.com'
- #port = '465' # for secure messages
- port = '587' # for normal messages
- if port == '465':
- server = smtplib.SMTP_SSL('{}:{}'.format(smtp_server_name, port))
- else :
- server = smtplib.SMTP('{}:{}'.format(smtp_server_name, port))
- server.starttls() # this is for secure reason
- server.login(sender, getpass(prompt="Email Password: "))
- server.send_message(msg)
- server.quit()
Add Comment
Please, Sign In to add comment