0

I am trying to make a mass texting application. The information for each person is stored in a mysql database (i.e. %phonenumber%@text.att.net). The idea is to get all the emails as a list and input it into this script. I'm not sure if I'm going about this right.

import sys
from smtplib import SMTP


def sendmail(toaddy, msg):              #toaddy is a list!!!!
    debuglevel = 0
    smtp = SMTP()
    smtp.set_debuglevel(debuglevel)
    smtp.connect('YOUR.MAIL.SERVER', 26)
    smtp.login('USERNAME@DOMAIN', 'PASSWORD')
    fromaddy = USERNAME@DOMAIN
    for user in toaddy                              
        smtp.sendmail(fromaddy, user, msg)
        smtp.quit()
4

1 に答える 1

0

最初のループの後、smtp セッションを終了しないでください。また、アドレスのリストをループする代わりに、ドキュメントは がsendmailリストを受け入れることを示しています:

def sendmail(toaddy, msg):  
    debuglevel = 0
    smtp = SMTP()
    smtp.set_debuglevel(debuglevel)
    smtp.connect('YOUR.MAIL.SERVER', 26)
    smtp.login('USERNAME@DOMAIN', 'PASSWORD')
    fromaddy = 'USERNAME@DOMAIN'
    smtp.sendmail(fromaddy, toaddy, msg)
    smtp.quit()
于 2012-11-21T19:47:48.290 に答える