#First, Importing the Simple Mail Transfer Protocol Module
import smtplib
#Specifying the From and To addresses
fromaddress = "fromaddress@gmail.com"
toaddress = "toaddress@gmail.com"
#Now,Specifying the Gmail Login
username = "yourgmail username"
password = "yourgmail password"
#Writing the message which will appear in the mail
message = """From:CodeScripter
...text here...
"""
#Creating a connection with the Gmail server
server =smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
#Creating a for loop to send multiple mails
for i in range (0,10):
server.sendmail(fromaddress,toaddress,message)
print "mail sent"
#closing the server
server.quit()
Thansk men, you rule!
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteIt gives me below error! What should i do to fix it
ReplyDeleteraise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials x6-v6sm14204701pfe.30 - gsmtp')
same here
Deletehow do i choose how many eamils i sends
ReplyDeleteif you change the last number in the range like in this example:
Deletefor i in range (0,44):
The Spam e-mail will be sent 44 times
works great thanks
ReplyDeleteChanging the value from `10` to any number you want your emails to go out should work.
ReplyDelete