如何使用xsmtplib代替smtplib发送邮件与xsmtplib一样,不要求输入登录密码

问题描述

根据pipy.org

使用xsmtplib的方法如下:

  from xsmtplib import SMTP<br/>
  server = SMTP(host="smtp.example.com",proxy_host="proxy.example.com")<br/>
  server.sendmail("user@example.com","admin@example.com","I have an issue. Please help!")<br/>
  server.quit()

但是我想先用密码登录然后发送。
类似于:

    server = xsmtplib.SMTP("smtp.gmail.com",587)<br/>
    server.ehlo()<br/>
    server.starttls()<br/>
    server.ehlo()<br/>
    server.login("xxxx@gmail.com","zzzzz")<br/>
    message = f"Dear Sir,\n\nThere is a price drop for your selected product. Current Price is {price}.\n Regards"<br/>
    server.sendmail("xxxx@gmail.com","yyyy@gmail.com",message)<br/>

解决方法

使用“ xsmtplib.xsmtplib.SMTP”其余部分的答案与smtplib相似。

server = xsmtplib.xsmtplib.SMTP("smtp.gmail.com",587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("xxxx@gmail.com","zzzzz")<br/>
message = f"Dear Sir,\n\nThere is a price drop for your selected product. Current Price is {price}.\n Regards"
server.sendmail("xxxx@gmail.com","yyyy@gmail.com",message)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...