-
-
Save yzhong52/d703ec82aeee24164f0c to your computer and use it in GitHub Desktop.
# smtplib module send mail | |
import smtplib | |
TO = '[email protected]' | |
SUBJECT = 'TEST MAIL' | |
TEXT = 'Here is a message from python.' | |
# Gmail Sign In | |
gmail_sender = '[email protected]' | |
gmail_passwd = 'password' | |
server = smtplib.SMTP('smtp.gmail.com', 587) | |
server.ehlo() | |
server.starttls() | |
server.login(gmail_sender, gmail_passwd) | |
BODY = '\r\n'.join(['To: %s' % TO, | |
'From: %s' % gmail_sender, | |
'Subject: %s' % SUBJECT, | |
'', TEXT]) | |
try: | |
server.sendmail(gmail_sender, [TO], BODY) | |
print ('email sent') | |
except: | |
print ('error sending mail') | |
server.quit() |
try to change the name of your file instead of mail.py
Do you have a python script for sending a personalized email to a group of emails one at a time
`import smtplib
li = ["[email protected]", "[email protected]"] #list of email_id to send the mail
for i in range(len(li)):
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
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() `
This is regarding multiple emails at once:
---- List of emials:
TO = "[email protected],[email protected],[email protected]"
---- change this line :
"s.sendmail("sender_email_id", li[i], message)"
---- For this line:
s.sendmail(sender_email_id, TO.split(","), message)
That helped a lot. Many thanks. =]
How to add Bcc?
Done I found a Way:
BODY = '\r\n'.join([ 'From: %s' % gmail_sender, 'Subject: %s' % SUBJECT, '', TEXT])
This code isn't working.