SMTP AUTH extension not supported by server

眉间皱痕 提交于 2020-05-09 18:40:08

问题


Using python I want to send email from my app but it shows the error

SMTP AUTH extension not supported by server

Code for the program,

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
fromaddr = "test1@example.com"
toaddr = "test2@example.com"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Test Mail"
body = "Test mail from python"
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.example.com', 25)
server.ehlo()
server.starttls()
server.ehlo()
server.login(fromaddr, "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()

Telnet Output:

ehlo test1.example.com
250-hidden
250-HELP
250-SIZE 104857600
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-STARTTLS
250 OK

I need to authenticate and send mail from app.


回答1:


a connection is required before login and sendemail.

server = smtplib.SMTP('smtp.example.com', 25)
server.connect("smtp.example.com",465)
server.ehlo()
server.starttls()
server.ehlo()
server.login(fromaddr, "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()



回答2:


It is probably just the server I was using, but was getting the same error as the OP even after implementing the accepted solution. Turned out the server did not want a login, so after deleting the line server.login(fromaddr, "password"), the error went away and it worked.




回答3:


There is no need to call smtp.connect() and smtp.ehlo(), because they are called automatically by SMTP() and smtp.starttls(). The issue is solved simply setting port to 587 instead of 28.

For client use, if you don’t have any special requirements for your security policy, it is highly recommended that you use the create_default_context() function to create your SSL context. It will load the system’s trusted CA certificates, enable certificate validation and hostname checking, and try to choose reasonably secure protocol and cipher settings.

In general, you will want to use the email package’s features to construct an email message, which you can then send via send_message().

import smtplib, ssl
from email.message import EmailMessage

msg = EmailMessage()
msg.set_content("The body of the email is here")
msg["Subject"] = "An Email Alert"
msg["From"] = "me@example.com"
msg["To"] = "you@example.com"

context=ssl.create_default_context()

with smtplib.SMTP("smtp.example.com", port=587) as smtp:
    smtp.starttls(context=context)
    smtp.login(msg["From"], "p@55w0rd")
    smtp.send_message(msg)



回答4:


import smtplib

s = smtplib.SMTP('smtplib.gmail.com',587)
s.ehlo()
s.starttls()
s.login('frmaddr','password')
try:
    s.sendmail('fromaddr','toaddr','message')
except:
    print (failed)



回答5:


The first tap is enable your gmail account to send emails by another applications, allow in this section:

https://myaccount.google.com/lesssecureapps

Then, you should can to send an email

import json 
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib

msg = MIMEMultipart()
message = "This is an email"

password = "yourpasswordemailsender"
msg['From'] = "emailsender@gmail.com"
msg['To'] = "emailsended@gmail.com"
msg['Subject'] = "Title of email"

msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(msg['From'], password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()



回答6:


you need to 'starttls' before login.



来源:https://stackoverflow.com/questions/37224073/smtp-auth-extension-not-supported-by-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!