Python - 发送电子邮件不起作用

时间:2016-09-16 13:54:20

标签: python sqlalchemy

所以我有一个我要发送消息的电子邮件列表。当我运行代码时,我没有收到任何错误,但电子邮件从未通过/这里是代码(我已经拥有所有必要的导入)

def notifyUsers():
    users = session.query(Users).all()

    From = 'status@travellrs.com'
    Subject = "Travellr - Feedback"
    Contents = '''
         If you are experiencing issues with Travellr, please email - ryanwaite28@gmail.com

    Thank You For Using Travellr!

    '''

    try:
        server = smtplib.SMTP('domain:port')
        server.starttls()
        server.login('login', 'password')

        for u in users:
            print (u.email)
            message = """\
            From: %s
            To: %s
            Subject: %s

            %s
            """ % \
            (From, ", ".join([u.email]), Subject, Contents)

            server.sendmail(From, [u.email], message)

        server.quit()
        print ('Emails Sent.')

    except Exception:
        print ('Error...')

0 个答案:

没有答案