Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Send an email with a gmail account using python 3
# smtplib module send mail
import smtplib
TO = ''
TEXT = 'Here is a message from python.'
# Gmail Sign In
gmail_sender = ''
gmail_passwd = 'password'
server = smtplib.SMTP('', 587)
server.login(gmail_sender, gmail_passwd)
BODY = '\r\n'.join(['To: %s' % TO,
'From: %s' % gmail_sender,
'Subject: %s' % SUBJECT,
'', TEXT])
server.sendmail(gmail_sender, [TO], BODY)
print ('email sent')
print ('error sending mail')
Copy link


This code isn't working.

Copy link

try to change the name of your file instead of

Copy link

Do you have a python script for sending a personalized email to a group of emails one at a time

Copy link

`import smtplib
li = ["", ""] #list of email_id to send the mail

for i in range(len(li)):
s = smtplib.SMTP('', 587)
s.login("sender_email_id", "sender_email_id_password")
message = "Message_you_need_to_send"
s.sendmail("sender_email_id", li[i], message)
s.quit() `

Copy link

This is regarding multiple emails at once:
---- List of emials:
TO = ",,"

---- change this line :
"s.sendmail("sender_email_id", li[i], message)"

---- For this line:
s.sendmail(sender_email_id, TO.split(","), message)

Copy link

That helped a lot. Many thanks. =]

Copy link

How to add Bcc?

Copy link

Done I found a Way:

BODY = '\r\n'.join([ 'From: %s' % gmail_sender, 'Subject: %s' % SUBJECT, '', TEXT])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment