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 a text from Python sawtooth500 2 141 Apr-14-2024, 01:56 PM
Last Post: sawtooth500
  Sending string commands from Python to a bluetooth device Rovelin 13 9,432 Aug-31-2021, 06:40 PM
Last Post: deanhystad
  How can I get Python Bulk Email Verification Script With API? zainalee 1 2,487 Jun-06-2021, 09:19 AM
Last Post: snippsat
  Need Outlook send email code using python srikanthpython 3 8,205 Feb-28-2021, 01:53 PM
Last Post: asyswow64
Video Python Bulk Email Verification Script With API Aj1128 0 2,618 Nov-28-2020, 11:38 AM
Last Post: Aj1128
  Sending Out Email via Python JoeDainton123 1 4,755 Aug-31-2020, 12:54 AM
Last Post: nilamo
  Including a Variable In the HTML Tags When Sending An Email JoeDainton123 0 1,869 Aug-08-2020, 03:11 AM
Last Post: JoeDainton123
  How to send email using python? Gigux 2 2,838 Jul-04-2020, 07:53 AM
Last Post: Gigux
  I am trying to send an email with python nick235 9 5,282 Jun-29-2020, 06:40 PM
Last Post: nick235
  Problem Sending a Dataset to a function Astrikor 2 1,835 Jun-10-2020, 08:09 AM
Last Post: Astrikor

Forum Jump:

User Panel Messages

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