def send_welcome_mail(post): delete_link = request.url_root[:-1] + url_for('delete', secret=post['secret']) html = render_template("welcome_mail.html", post=post, delete_link=delete_link) msg = Message((app.config['EMAIL'], app.config['WEBSITE_NAME']), u"ברוך הבא ללחזור!", html=html) msg.add_to(post['email'], post['name']) if not app.debug: print "Sent mail to", post['email'], mail.smtp.send(msg)
def testemail(): http = Http('tongbupan_test_register1','register2012',ssl=True) fromemail = ('*****@*****.**','tesst') message = Message(fromemail,'test email',text='test email content') message = message.add_to('*****@*****.**') try: ret = http.send(message) if ret: print 'ret:%s'%ret except Exception,e: print 'error'
def send_complete_email(self, **kwargs): #/user/parentcomplete jsonData = json.loads(self.request.body) userid = long(jsonData['id']) result = {'status':'Error', 'u_login': bool(False), 'message':''} result = User.get_entity(userid, result) to_addr = result['parent_email'] if not mail.is_email_valid(to_addr): # Return an error message... result['status'] = 'fail' pass type_1 = "parent" url_monitor = self.uri_for('user_monitor', type=type_1, id=userid) strMessage = "Dear Parent, \n\ \n\ Thank you for allowing your child, "+ result['u_name'] + ", to participate in using K-Sketch. \n\ \n\ To view your child's sketches, click on: " + "http://" + _ConfigDefaults.ksketch_HOSTNAME + url_monitor + "\n\ \n\ Please bookmark this link to easily access your child's profile in the future.\n\ \n\ \n\ K-Sketch Team" # make a secure connection to SendGrid s = Sendgrid(_ConfigDefaults.ksketch_SENDGRID_username, _ConfigDefaults.ksketch_SENDGRID_password, secure=True) # make a message object msg = Message(_ConfigDefaults.ksketch_EMAIL, "K-Sketch: Registration Complete", strMessage, "") # add a recipient msg.add_to(to_addr) # use the Web API to send your message s.web.send(msg) #message.send() return self.respond(result)
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 send_emails(data): """Send sign-up e-mails.""" if data['is_interested']: us_subj = 'New Leader' us_body = render_template('leader-us.html', **data) else: us_subj = 'New Pledge' us_body = render_template('pledge-us.html', **data) them_subj = 'Congrats on pledging to disconnect!' them_body = render_template('pledge-them.html', **data) them_msg = Message(BYLINE, them_subj, them_body, them_body) them_msg.add_to(data['email'], data['name']) sg.smtp.send(them_msg) us_msg = Message(BYLINE, '[PDC] %s' % us_subj, us_body, us_body) us_msg.add_to(EMAIL, NAME) us_msg.set_replyto(data['email']) # Reply-to them by default sg.smtp.send(us_msg)
def send_contact_mail(subject, text, name, email): msg = Message((email, name), subject, html="<div dir='rtl'>" + text + "</div>") msg.add_to((app.config['EMAIL'], app.config['WEBSITE_NAME'])) if app.debug: success = True else: success = mail.smtp.send(msg) print "Sent contact mail", success html = render_template("contact_confirmation.html", success=success, name=name, subject=subject, to=app.config['WEBSITE_NAME']) msg = Message((app.config['EMAIL'], app.config['WEBSITE_NAME']), u'הודעתך נשלחה', html=html) msg.add_to((email, name)) if app.debug: return True else: print "Sent confirmation mail", mail.smtp.send(msg) return success
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
def send_approval_email(self, **kwargs): #user/parentapproval utc = UTC() result = {'status':'Error', 'u_login': bool(False), 'message':''} auser = self.auth.get_user_by_session() if auser: userid = auser['user_id'] if userid: result = User.get_entity(userid, result) result['u_login'] = bool(True) to_addr = result['parent_email'] #generate random string alphabet = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" pw_length = 50 token_approve = "" token_disapprove = "" type_1 = "approve" type_2 = "disapprove" for i in range(pw_length): next_index1 = random.randrange(len(alphabet)) next_index2 = random.randrange(len(alphabet)) token_approve = token_approve + alphabet[next_index1] token_disapprove = token_disapprove + alphabet[next_index2] url_approve = self.uri_for('user_approval', type=type_1, token=token_approve, id=userid) url_disapprove = self.uri_for('user_approval', type=type_2, token=token_disapprove, id=userid) if not mail.is_email_valid(to_addr): # Return an error message... result['status'] = 'fail' pass strMessage = "Dear Parent, \n\ \n\ K-Sketch would like to request permission for your child, "+ result['u_name'] + ", to participate in using our system. \n\ \n\ Please click the following link to activate your child's account: " + "http://" +_ConfigDefaults.ksketch_HOSTNAME + url_approve + "\n\ \n\ Please click the following link to cancel participation: " + "http://"+_ConfigDefaults.ksketch_HOSTNAME + url_disapprove + "\n\ \n\ \n\ K-Sketch Team" # make a secure connection to SendGrid s = Sendgrid(_ConfigDefaults.ksketch_SENDGRID_username, _ConfigDefaults.ksketch_SENDGRID_password, secure=True) # make a message object msg = Message(_ConfigDefaults.ksketch_EMAIL, "K-Sketch: Approval for Registration", strMessage, "") # add a recipient msg.add_to(to_addr) # use the Web API to send your message s.web.send(msg) #message.send() return self.respond(result)