相关疑难解决方法(0)

如何使用Python以Gmail作为提供商发送电子邮件?

我正在尝试使用python发送电子邮件(Gmail),但我收到以下错误.

Traceback (most recent call last):  
File "emailSend.py", line 14, in <module>  
server.login(username,password)  
File "/usr/lib/python2.5/smtplib.py", line 554, in login  
raise SMTPException("SMTP AUTH extension not supported by server.")  
smtplib.SMTPException: SMTP AUTH extension not supported by server.
Run Code Online (Sandbox Code Playgroud)

Python脚本如下.

import smtplib
fromaddr = 'user_me@gmail.com'
toaddrs  = 'user_you@gmail.com'
msg = 'Why,Oh why!'
username = 'user_me@gmail.com'
password = 'pwd'
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
Run Code Online (Sandbox Code Playgroud)

python email gmail smtp

272
推荐指数
10
解决办法
31万
查看次数

Python smtplib安全性

我正在尝试使用电子邮件python脚本,并且想知道在编写基于python的电子邮件脚本时它是否不太安全,而不是在登录网页时通过互联网发送凭据时?在下面的脚本中,用户是否明确传递?

import smtplib
from email.mime.text import MIMEText

GMAIL_LOGIN = 'xxxxxx@gmail.com'
GMAIL_PASSWORD = 'amiexposed?'

def send_email(subject, message, from_addr=GMAIL_LOGIN, to_addr=GMAIL_LOGIN):
    msg = MIMEText(message)
    msg['Subject'] = 'Test message'
    msg['From'] = from_addr
    msg['To'] = to_addr

    server = smtplib.SMTP('smtp.gmail.com',587)
    server.ehlo()
    server.starttls()
    server.ehlo()
    server.login(GMAIL_LOGIN,GMAIL_PASSWORD)
    server.sendmail(from_addr, to_addr, msg.as_string())
    server.close()

if __name__ == '__main__':
    send_email('testing email script', 'This is a test message')
Run Code Online (Sandbox Code Playgroud)

python

6
推荐指数
1
解决办法
2752
查看次数

标签 统计

python ×2

email ×1

gmail ×1

smtp ×1