Reputation: 41
I want to send email in python and the following code works. However I want to send the email as a google group. Since a google group has no password, I am not able to login to the server. Is there anyway I can go about this?
def sendEmail(self, toEmail, subject, message ):
msg = MIMEMultipart()
password = "*****"
msg['From'] = "[email protected]"
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']))
Upvotes: 4
Views: 2695
Reputation: 46
You need to add group address as allowed send-as address in Gmail settings. Then you'll be able to use group address as "From" address. Authentication should still be done with your (non-group) address, of course.
Upvotes: 0
Reputation: 2025
It sends like you should use a Service Account to send the email on your behalf.
Here is a pretty good guide (not written by me): https://medium.com/lyfepedia/sending-emails-with-gmail-api-and-python-49474e32c81f
Upvotes: 1