[Python] Send an email from gmail with two-step verification set

Set app password with gmail

https://support.google.com/accounts/answer/185833?hl=ja Just set from here. You can get a 16-digit app password.

Email sending sample code

# -*- coding: utf-8 -*-

import smtplib
from email.mime.text import MIMEText

if __name__ == '__main__':
    to_addr = '[email protected]'
    from_addr = '[email protected]'
    mail_id = from_addr
    #Enter the obtained 16-digit password
    mail_pass = 'wwwwxxxxyyyyzzzz'

    message = MIMEText('Hello')
    message['Subject'] = 'Hello'
    message['From'] = from_addr
    message['To'] = to_addr

    sender = smtplib.SMTP_SSL('smtp.gmail.com')
    sender.login(mail_id, mail_pass)
    sender.sendmail(from_addr, to_addr, message.as_string())
    sender.quit()

Recommended Posts

[Python] Send an email from gmail with two-step verification set
[Python] Send an email with outlook
Send email via gmail with Python 3.4.3.
Send an email with Amazon SES + Python
Send email with Python
Send an email to Spushi's address with python
Send an email with Excel attached in Python
Send Japanese email with Python3
Send using Python with Gmail
To automatically send an email with an attachment using the Gmail API in Python
I tried sending an email from Amazon SES with Python
[Automation] Send Outlook email with Python
Note: Send an email with Django
HTML email with image to send with python
I tried sending an email with python.
Scraping from an authenticated site with python
[Python] Send email
[Python] Send email
What to do if you couldn't send an email to Yahoo with Python.
Send an email to a specific email address with python without SMTP settings
I tried to send a registration completion email from Gmail with django.
Output the report as PDF from DB with Python and automatically attach it to an email and send it
I want to email from Gmail using Python.
Generate an insert statement from CSV with Python.
I tried sending an email with SendGrid + Python
I want to send Gmail with Python, but I can't because of an error
Send an email directly by pulling an MX record from your email address in Python
Send email with Django
Validate E-Mail with Python
Send Gmail in Python
Get mail from Gmail and label it with Python3
If you can't send an email with python smtplib and have trouble, command line
[Python] Send gmail with python: Send one by one with multiple image files attached
Creating an egg with python
Send email in Python (Outlook)
With skype, notify with skype from python!
Try to extract a character string from an image with Python3
I tried sending an email from the Sakura server with flask-mail
Cut out an image with python
Call C from Python with DragonFFI
Using Rstan from Python with PypeR
Install Python from source with Ansible
Create folders from '01' to '12' with python
Operate an I2C-connected display from Python
Set python compile options with pyenv
Create an Excel file with Python3
I sent an SMS with Python
Easy email sending with haste python3
Run Aprili from Python with Orange
Call python from nim with Nimpy
Draw an illustration with Python + OpenCV
Read fbx from python with cinema4d
Send multipart / form-data with python requests
Easily send emails with Gmail with Django
Send image with python, save with php
[Python] Create API to send Gmail
Send email with SES in Python and short message with SMS on SNS
Send mail with mailx to a dummy SMTP server set up with python.
Try sending an email with the Gmail API Client Library for Java
Collecting information from Twitter with Python (Twitter API)
[Python] Building an environment with Anaconda [Mac]