我正在尝试使用smtp server从python发送电子邮件,但是会抛出
错误。我该如何解决?
我也获得了gmail的许可才能使用此功能
这是代码

import smtplib


content='Hello I am just checking email.'
mail=smtplib.SMTP('smtp.gmail.com',587)
mail.ehlo()
mail.starttls()
mail.login('My email','Mypassword')
mail.send('From email','destiation password',content)
mail.close()


这段代码通过这个错误
    TypeError:send()接受2个位置参数,但给出了4个

请修复此错误。

最佳答案

sendmail是您应该使用的:

smtplib.SMTP.sendmail(self, from_addr, to_addrs, msg, mail_options=[], rcpt_options=[])



  此命令执行整个邮件事务。
  
  参数为:


- from_addr    : The address sending this mail.
- to_addrs     : A list of addresses to send this mail to.  A bare
                 string will be treated as a list with 1 address.
- msg          : The message to send.
- mail_options : List of ESMTP options (such as 8bitmime) for the
                 mail command.
- rcpt_options : List of ESMTP options (such as DSN commands) for
                 all the rcpt commands.

关于python - 从Python发送电子邮件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48019851/

10-10 17:49
查看更多