in your models.

mail = auth.settings.mailer
mail.settings.server = "your_smtp_server_and:port"
mail.settings.sender = "y...@you.com"
mail.settings.login = "y...@you.com:password"

# sends an verification e-mail upon registration
auth.settings.registration_requires_verification = True


def send_email(user, subject):
    message = """ Multi line string for %(first_name)s......"
    message = open("somefile.html", "r").read()
    # you also have the option to include everyone in bcc=[...]
    mail.send(to=user.email,
                   subject=subject,
                   message=message % user)


Now in any place like controllers or scripts

users = db(db.auth_user).select()
for user in users:
    send_email(user, "some subject")


Dont forget to keep track of sent emails, use try: except... try to not use
gmail for more than 500 recipients.




If you want an email to be send everytime a user login in your page

auth.settings.login_onaccept = lambda form: mail.send(to=form.vars.email,
subject="%(first_name)s logged in" % form.vars, message="User logged in %s"
% str(form.vars))

-- 



Reply via email to