
from flask_mail import Message

from openspending.core import mail
from openspending.lib.helpers import url_for

def generate_hashlink(account):
    return url_for('account.verify', login=account.login_hash, _external=True)


def sendhash(account, gettext = False):
    msg = Message(subject="FIND.state.gov Login URL",
              recipients=[account.email],
              body = "You're getting this email because it was entered on FIND.state.gov.  \
              Use the this link to login as a USG user.  \
              This is a private link just for you, so do not forward it.\
              " + generate_hashlink(account))
    if gettext:
        returnobj = {
            "subject": "FIND.state.gov Login URL",
            "recipients":[account.email],
            "body":  "You're getting this email because it was entered on FIND.state.gov.  \
              Use the this link to login as a USG user.  \
              This is a private link just for you, so do not forward it.\
              " + generate_hashlink(account),
            "verifylink": generate_hashlink(account)
        }
        return returnobj
    mail.send(msg)
@@ -1119,16 +1119,29 @@
 turnobj%0A
+    try:%0A    
     mail
@@ -1150,8 +1150,92 @@
 end(msg)
+%0A    except Exception ,e:%0A        print %22failed to send the message%22%0A        print e

make sure we don't need an smtp for development/beta