import smtplib
email_user = 'myemail'
email_send = 'myemail'
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login( email_user, "PASSWORD")
msg = "Hello"
server.sendmail(email_user,email_send, msg)
server.quit()
错误讯息:
Traceback (most recent call last): File "python", line 7, in socket.gaierror: [Errno -2] Name or service not known
我正在使用Repl.it;这是不工作的原因吗?
答案 0 :(得分:0)
import smtplib
import email
from email.MIMEMultipart import MIMEMultipart
from email.Utils import COMMASPACE
from email.MIMEBase import MIMEBase
from email.parser import Parser
from email.MIMEImage import MIMEImage
from email.MIMEText import MIMEText
from email.MIMEAudio import MIMEAudio
import mimetypes
def send(user, password, fromaddr, to, subject, body):
smtp_host = 'smtp.gmail.com'
smtp_port = 587
server = smtplib.SMTP()
server.connect(smtp_host,smtp_port)
server.ehlo()
server.starttls()
server.login(user, password)
msg = email.MIMEMultipart.MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = email.Utils.COMMASPACE.join(to)
msg['Subject'] = subject
msg.attach(MIMEText(body))
server.sendmail(user,to,msg.as_string())