Python 3 |发送电子邮件-SMTP-gmail-错误:SMTPException [英] Python 3 | Send email -- SMTP -- gmail -- Error : SMTPException

查看:399
本文介绍了Python 3 |发送电子邮件-SMTP-gmail-错误:SMTPException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python 3发送电子邮件.我还无法理解我所看到的示例.这里是一个参考:使用Python发送电子邮件

I want to send an email by use of Python 3. I cannot yet make sense of the examples that I have seen. Here is one reference: Using Python to Send Email

我已经提取了以上参考文献中找到的第一个简单示例.我发现此示例很好地表示了我在互联网上看到的示例组合.这似乎是我要尝试做的基本形式.

I have pulled the first simple example found on the above reference. I find this example a good representation of the combination of examples I have seen on the internet. It seems to be the basic form of doing what I am trying to do.

当我尝试下面的代码时,我收到错误消息:

When I try the code below, I receive Error:

File "C:\Python33\Lib\email.py", line 595, in login
    raise SMTPException("SMTP AUTH extension not supported by server.")
smtplib.SMTPException: SMTP AUTH extension not supported by server.

这是代码:

# Send Mail

import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)

# Log in to the server
server.login("myEmail@gmail.com","myPassword")

# Send mail
msg = "\nHello!"
server.sendmail("myEmail@gmail.com","recipient@gmail.com", msg)

推荐答案

我在YouTube上找到了解决方案.

I have found a solution on YouTube.

这是视频链接

# smtplib module send mail

import smtplib

TO = 'recipient@mailservice.com'
SUBJECT = 'TEST MAIL'
TEXT = 'Here is a message from python.'

# Gmail Sign In
gmail_sender = 'sender@gmail.com'
gmail_passwd = 'password'

server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(gmail_sender, gmail_passwd)

BODY = '\r\n'.join(['To: %s' % TO,
                    'From: %s' % gmail_sender,
                    'Subject: %s' % SUBJECT,
                    '', TEXT])

try:
    server.sendmail(gmail_sender, [TO], BODY)
    print ('email sent')
except:
    print ('error sending mail')

server.quit()

这篇关于Python 3 |发送电子邮件-SMTP-gmail-错误:SMTPException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆