Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

looping emails using a database with python code

import smtplib
    import MySQLdb

    SERVER = "localhost"

    FROM = "sender@example.com"
    TO = ["user@example.com","another@user.com","many@users.com"] 

    #SQL data access part
    db = MySQLdb.connect(host='localhost', user='root', passwd='$$', db='emaildatabase')
    cursor = db.cursor()
    cursor.execute('select email from tablename where email is not null')
    db.commit()
    rows = cursor.fetchall()
    for item in rows:
        TO.append(item)

    SUBJECT = "Hello!"

    TEXT = "This message was sent with Python's smtplib."

    # Prepare actual message
    message = """
    From: %s
    To: %s
    Subject: %s

    %s
    """ % (FROM, ", ".join(TO), SUBJECT, TEXT)

    # Send the mail

    server = smtplib.SMTP(SERVER)
    server.sendmail(FROM, TO, message)
    server.quit()
Comment

PREVIOUS NEXT
Code Example
Python :: Set symmetric Using the Symmetric Difference Operator (^) Method 
Python :: pip install time python 
Python :: BIDS extract JSON data 
Python :: Find Factors of a Number Using for Loop 
Python :: Validation using voluptuous python library 
Python :: Simple Python Permutation Printing result without for loop 
Python :: negative list slicing 
Python :: how to change multiple index in list in python 
Python :: pyqt global hotkey 
Python :: glom safely interact with dictionary 
Python :: how to find the index of a specific number in pythong? 
Python :: pandas version for python 3.9 
Python :: bulet in jupyter notebook 
Python :: python certificate verify failed unable to get local issuer certificate nltk 
Python :: python new set 
Python :: keyword only arguments python 
Python :: Python NumPy ndarray flat function Example 
Python :: manipulate sns legend 
Python :: Python NumPy asfortranarray Function Tuple to an array 
Python :: django on-delete options 
Python :: fpdf latin-1 
Python :: Python __sub__ magic method 
Python :: function nbYear(p0, percent, aug, p) { let n = 0; while(p0 < p) { p0 = p0 + Math.round(p0 * (percent/100)) + aug; n ++; } return n; } 
Python :: NumPy invert Code When the input is a number 
Python :: ttk.frame 
Python :: gensim prepare corpus 
Python :: how to do alignment of fasta in biopython 
Python :: pygame getting your charecter to jump 
Python :: browser environment: 
Python :: object get in djangi 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =