def send_user_email(user, verification): """Send an email for user sign up or another action. This method encapsulates email handling of the application. It proxies to other methods that correspond to specific actions required for the message being handled. Parameters ---------- :user: The user's information to personalize the email. :verification: The verification token for verifying a new user. This method actually sends the email that is generated and does not return anything. """ # TODO i18n this stuff! message_text = \ "Thank you for registering for Margarine. We hope you enjoy " \ "the services provided.\n" \ "\n" \ "Please, verify your human status by visiting the following " \ "URL: {verification_url}\n" \ "\n" \ "\n" \ "Thanks,\n" \ "\n" \ "Margarine\n" logger.debug('blend URL: %s', PARAMETERS['blend.url']) from margarine.blend import BLEND # TODO Figure out looping import. BLEND.config["SERVER_NAME"] = PARAMETERS['blend.url'] with BLEND.app_context(): message = email.mime.text.MIMEText(message_text.format(verification_url = url_for("user.users_password_api", username = user["username"], verification = verification))) message["Subject"] = "Margarine Verification" message["From"] = "Margarine Verifications <" + PARAMETERS["email.from"] + ">" message["To"] = "{0} <{1}>".format(user.get('name'), user['email']) uri = URI(PARAMETERS["email.url"]) logger.info("Connecting to SMTP Server.") _ = smtplib.SMTP(uri.host, uri.port) if uri.username is not None: _.login(uri.username, uri.password) _.sendmail(PARAMETERS["email.from"], [ user["email"] ], message.as_string()) _.quit() logger.info("Successfully sent email!")
def setUp(self): super(BaseBlendTest, self).setUp() BLEND.config['TESTING'] = True self.application = BLEND.test_client()