If you can't send an email with python smtplib and have trouble, command line

When smtplib does not connect, the status is difficult to understand if it is a program. In such a case, if you use python cli, a response will be displayed and you can quickly understand what to do and solve it.

$ python3

import smtplib
import ssl
from email.mime.text import MIMEText

port = 465
jp = 'iso-2022-jp'
smtp_server = "SMTP server.somewhere"
sender_email = 'Email@address'
password = "**********"
receiver_emails = 'Someone's@mail address'

message = 'hello world'
msg = MIMEText(message, jp)
msg['Subject'] = "Notice"
msg['From'] = sender_email
msg['To'] = receiver_emails

server = smtplib.SMTP_SSL(smtp_server, port)

server.ehlo()
>> (250, b'xxx(SMTP server) xxxxxxxx\nAUTH LOGIN CRAM-MD5 PLAIN\nAUTH=LOGIN CRAM-MD5 PLAIN\nPIPELINING\n8BITMIME')
#Since it says AUTH LOIN, why not log in? !! !!

server.login(sender_email, password)
>> (235, b'ok, go ahead (#2.0.0)')

server.sendmail(sender_email, receiver_emails, msg.as_string())
>> {}

The email is now being sent. For receiver_emails, you can send emails to multiple people by passing them in a list.

Recommended Posts

If you can't send an email with python smtplib and have trouble, command line
What to do if you couldn't send an email to Yahoo with Python.
Send an email with Amazon SES + Python
Send an email to Spushi's address with python
Send an email with Excel attached in Python
Send email with Python
What to do if you run python in IntelliJ and end with an error
Send Japanese email with Python3
[Python] Send an email from gmail with two-step verification set
What to do if you can't install pyaudio with pip #Python
[Automation] Send Outlook email with Python
Note: Send an email with Django
Send email via gmail with Python 3.4.3.
Output the report as PDF from DB with Python and automatically attach it to an email and send it
Send an email to a specific email address with python without SMTP settings
Send email with SES in Python and short message with SMS on SNS
HTML email with image to send with python
I tried sending an email with python.
I want to send Gmail with Python, but I can't because of an error
What to do if you get an error when installing python with pyenv
To automatically send an email with an attachment using the Gmail API in Python
Send a message to LINE with Python (LINE Notify)
Trouble with Python pseudo-private variables and class inheritance
What are you comparing with Python is and ==?
I tried sending an email with SendGrid + Python
If you get lost with HTTP redirects 301 and 302
What to do if you get an OpenSSL error when installing Python 2 with pyenv
[Python] Send email
[Python] Send email
python2 series / 3 series, character code and print statement / command line
I made a LINE BOT with Python and Heroku
mac OS X 10.15.x pyenv Python If you can't install
Email hipchat with postfix, fluentd and python on Azure
If you have trouble importing between folders when creating a package with Cython, see this.