code mail pythom

  1. # code bom mail by Kevin Kien
  2. import os
  3. import smtplib
  4. import sys
  5. server = raw_input ('Server Mail: ')
  6. user = raw_input('Username: ')
  7. passwd = raw_input('Password: ')
  8. to = raw_input('To: ')
  9. subject = raw_input('Subject: ')
  10. body = raw_input('Message: ')
  11. total = input('Number of send: ')
  12. if server == 'gmail':
  13.     smtp_server = 'smtp.gmail.com'
  14.     port = 587
  15. elif server == 'yahoo':
  16.     smtp_server = 'smtp.mail.yahoo.com'
  17.     port = 25
  18. else:
  19.     print 'Applies only to gmail and yahoo.'
  20.     sys.exit()
  21. print ''
  22. try:
  23.     server = smtplib.SMTP(smtp_server,port)
  24.     if smtp_server == "smtp.gmail.com":
  25.             server.starttls()
  26.     server.login(user,passwd)
  27.     for i in range(1, total+1):
  28.         subject = os.urandom(9)
  29.         msg = 'From: ' + user + '\nSubject: ' + subject + '\n' + body
  30.         server.sendmail(user,to,msg)
  31.         print "\rTotal emails sent: %i" % i
  32.         sys.stdout.flush()
  33.     server.quit()
  34.     print '\n Done !!!'
  35. except KeyboardInterrupt:
  36.     print '[-] Canceled'
  37.     sys.exit()
  38. except smtplib.SMTPAuthenticationError:
  39.     print '\n[!] The username or password you entered is incorrect.'
  40.     sys.exit()