【问题标题】:Send an email as a google group from python从 python 以 google 组的形式发送电子邮件
【发布时间】:2018-05-22 19:12:01
【问题描述】:

我想在 python 中发送电子邮件,以下代码有效。但是我想将电子邮件作为谷歌组发送。由于 google 组没有密码,我无法登录服务器。无论如何我可以解决这个问题吗?

def sendEmail(self, toEmail, subject, message ):
    msg = MIMEMultipart()
    password = "*****"
    msg['From'] = "abc@gmail.com"
    msg['To'] = toEmail
    msg['Subject'] = subject
    msg.attach(MIMEText(message, 'plain'))
    server = smtplib.SMTP('smtp.gmail.com: 587')
    server.starttls()
    server.login(msg['From'],password)

    server.sendmail(msg['From'], msg['To'].split(","), msg.as_string())
    server.quit()
    logging.debug('sent email to %s', (msg['To']))

【问题讨论】:

    标签: python email smtp starttls


    【解决方案1】:

    它发送就像您应该使用服务帐户代表您发送电子邮件一样。

    这是一个很好的指南(不是我写的):https://medium.com/lyfepedia/sending-emails-with-gmail-api-and-python-49474e32c81f

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2013-04-02
      相关资源
      最近更新 更多