【发布时间】: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