smtplib
.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)
pip3 install smtplib
python3 main.py
True
Recommended Posts