Python Forum
Problem in sending email using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem in sending email using python
#1
import re
import smtplib
from email.mime.text import MIMEText
import cvs

fp = open('message.txt', 'rb')
msg = MIMEText(fp.read())
fp.close()
msg['Subject'] = 'Subject goes here'
msg['From'] = '[email protected]'

server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login('[email protected]', 'password')
email_data = csv.reader(open('email.csv', 'rb'))
email_pattern= re.compile("^.+@.+\..+$")
for row in email_data:
if( email_pattern.search(row[1]) ?
del msg['To']
msg['To'] = row[1]
try:
server.sendmail('[email protected]', [row[1]], msg.as_string())
except SMTPException:
print "An error occured."
server.quit()
I just did some amendment in this code and it is working but could you tell me how I set interval between each email sent because I don't want to send it once instead want to keep interval of 5 to 10 min in each email.

PS: If you could set email rotation then I would highly appreciate. Email rotation means suppose; I have one email format " Email format " and want to send it via email a , b,c ,d i mean just want a rotation first email sent by [email protected] then [email protected] again [email protected] .... then again a@gmail i mean like rotation of email id so that i can send more email with different email ids in same time.
Reply
#2
Hello there, firstly i am random guy from internet trying to help
because of missing intents in source i assumed the code as following one =>
import time
...
for row in email_data:
    if( email_pattern.search(row[1]) ? del msg['To']:
       msg['To'] = row[1]
       try:
           server.sendmail('[email protected]', [row[1]], msg.as_string())
       except SMTPException:
           print "An error occured."
       time.sleep(600)
server.quit()
Line 1,10 came to my mind as simplest solution to problem but i am not sure if google will keep connection alive for 10 minutes.

Speaking of more reliable solution i would recommend a cron job that runs script every 5-10 minutes Cron job
And for user indexing i would use simple .ini or json configuration with list of users and index variable python configparser
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending email using own smtp server robertkwild 11 6,335 Jul-05-2024, 12:59 AM
Last Post: AdamHensley
  Sending a text from Python sawtooth500 2 1,151 Apr-14-2024, 01:56 PM
Last Post: sawtooth500
  Sending string commands from Python to a bluetooth device Rovelin 13 15,916 Aug-31-2021, 06:40 PM
Last Post: deanhystad
  How can I get Python Bulk Email Verification Script With API? zainalee 1 3,111 Jun-06-2021, 09:19 AM
Last Post: snippsat
  Need Outlook send email code using python srikanthpython 3 11,255 Feb-28-2021, 01:53 PM
Last Post: asyswow64
Video Python Bulk Email Verification Script With API Aj1128 0 3,158 Nov-28-2020, 11:38 AM
Last Post: Aj1128
  Sending Out Email via Python JoeDainton123 1 6,623 Aug-31-2020, 12:54 AM
Last Post: nilamo
  Including a Variable In the HTML Tags When Sending An Email JoeDainton123 0 2,584 Aug-08-2020, 03:11 AM
Last Post: JoeDainton123
  How to send email using python? Gigux 2 3,787 Jul-04-2020, 07:53 AM
Last Post: Gigux
  I am trying to send an email with python nick235 9 7,437 Jun-29-2020, 06:40 PM
Last Post: nick235

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020