def send_notification(self, subject, message, recipient=None): subject = subject or DEFAULT_NOTIFICATION_SUBJECT try: self._ensure_sg_initialized() logger.info("Sending notification email...") s_message = Message(self.from_address, subject=subject, text=message) to_address = listify(recipient or self.to_address) for address in to_address: s_message.add_to(address) self._sendgrid.web.send(s_message) logger.info("Email sent successfully!") except Exception, e: print e print traceback.format_exc() logger.error("Error while sending email:\n%s" % traceback.format_exc())
def post(self): user = users.get_current_user() if user is None: self.redirect('/') # get values from form subject = cgi.escape(self.request.get('subject')) toAddress = cgi.escape(self.request.get('toAddress')) content = cgi.escape(self.request.get('content')) # make a secure connection to SendGrid # <sendgrid_username>,<sendgrid_password> should be replaced with the SendGrid credentials s = Sendgrid('<sendgrid_username>', '<sendgrid_password>', secure=True) message = None # make a message object try: # update the <from_address> with your email address message = Message('<from_address>', subject, content, '') except Exception, msg: response = msg pass