Easy email sending with haste python3

Send email with python3

environment

Source

main.py


import smtplib
from email.mime.text import MIMEText

TO_ADDRESS = "Destination [email protected]"
FROM_ADDRESS = "Source [email protected]"
MY_PASSWORD = "Source address password"

def send_mail(msg):
    try:
        smtpobj = smtplib.SMTP('smtp.gmail.com', 587)
        smtpobj.ehlo()
        smtpobj.starttls()
        smtpobj.ehlo()
        smtpobj.login(FROM_ADDRESS, MY_PASSWORD)
        smtpobj.sendmail(FROM_ADDRESS, TO_ADDRESS, msg.as_string())
        smtpobj.close()
        return True
    except:
        return False

if __name__ == '__main__':
    msg = MIMEText("Test body")
    msg['Subject'] = "test"
    msg['From'] = FROM_ADDRESS
    msg['To'] = TO_ADDRESS

    result = send_mail(msg)
    print(result)

how to use

  1. Module installation pip3 install smtplib
  2. Script execution python3 main.py

result

True

Recommended Posts

Easy email sending with haste python3
I tried sending an email with python.
Validate E-Mail with Python
Send email with Python
I tried sending an email with SendGrid + Python
Send Japanese email with Python3
[Co-occurrence analysis] Easy co-occurrence analysis with Python! [Python]
Easy folder synchronization with Python
Easy Python compilation with NUITKA-Utilities
Easy HTTP server with Python
[Python] Easy parallel processing with Joblib
I tried sending an email from Amazon SES with Python
Debug email sending with Python's smtpd.DebuggingServer
[Automation] Send Outlook email with Python
Easy Python + OpenCV programming with Canopy
Bayesian optimization very easy with Python
Easy data visualization with Python seaborn.
Easy parallel execution with python subprocess
Easy modeling with Blender and Python
[Python] Send an email with outlook
Send email via gmail with Python 3.4.3.
Easy keyword extraction with TermExtract for Python
[Python] Super easy test with assert statement
[Python] Easy argument type check with dataclass
HTML email with image to send with python
Easy introduction of speech recognition with Python
[Easy Python] Reading Excel files with openpyxl
Easy web app with Python + Flask + Heroku
Easy image processing in Python with Pillow
[Easy Python] Reading Excel files with pandas
Send an email with Amazon SES + Python
Easy web scraping with Python and Ruby
[Python] Easy Reinforcement Learning (DQN) with Keras-RL
Python 3.6 email library
FizzBuzz with Python3
Scraping with Python
Python is easy
Statistics with python
Scraping with Python
Python with Go
[Python] Send email
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
[Python] Send email
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
[Python] Easy introduction to machine learning with python (SVM)
Send an email to Spushi's address with python
Extract email attachments received in Thunderbird with Python
Send an email with Excel attached in Python
Easy Lasso regression analysis with Python (no theory)
Make your Python environment "easy" with VS Code
✨ Easy with Python ☆ Estimated elapsed time after death ✨