def send_mail(self): if self.parent is None: # 评论博客 subject = '有人评论你的博客' # 发送给这篇博客的作者, 在Blog.models中,重写的方法 email = self.content_object.get_email() else: # 回复评论 subject = '有人回复你的评论' email = self.reply_to.email # 如果邮箱不为空 if email != '': # 使用reverse反向解析被评论的是哪一篇博客的链接地址,在Blog.models中,重写的方法 # text = self.text + '\n' + self.content_object.get_url() # 优化上面,写成html代码,进行修饰 # text = '%s\n <a href="%s">%s</a>' % (self.text, self.content_object.get_url()) # 进一步优化上面,使用html模板,虽然不太懂,和模板的传值方式一样 context = {} context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render_to_string('comment/send_mail.html', context) # ???? 反正这个p是去不掉了。。。 # text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') # 发送验证码邮件,使用多线程 send_mail = SendMail(subject, text, email) # 开始多线程 send_mail.start()
def send_mail(self): if self.parent is None: #评论 suject = "有人评论你的 博客" #models 也一个方法返回一个email email = self.content_object.get_email() else: #回复 suject = "有人回复你的 博客" email = self.reply_to.email if email != "": # 反向解析url 得到地址reverse("shahu_detail", args=[comment.content_object.pk]) # 或者设置models方法 #text = '%s\n<a href="%s">%s</a>' % (self.text, self.content_object.get_url(), "点击查看") #使用模版 content = {} content["comment_text"] = self.text content["url"] = self.content_object.get_url() text = render_to_string("comment/send_email.html", content) # 发送邮件 === 移植到上边多线程 #send_mail(suject, text, settings.EMAIL_HOST_USER, [email], fail_silently=False) #断电测试 #import pdb #pdb.set_trace() #命令行exit()退出 继续执行 #多线程执行 send_mail = Sendmail(suject, text, email) send_mail.start()
def send_email(sender, instance, **kwargs): if not instance.parent is None: subject = '有人回复了你的评论' # 邮件主题 email = instance.reply_to.email # 收件人 if email != '': # 邮件内容 context = {} context['comment_text'] = instance.text context['url'] = instance.content_object.get_url() text = render_to_string('comment/send_mail.html', context) send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if self.parent is None: subject = '有人评论你的博客' email = self.content_object.get_email() else: subject = '有人回复你的评论' email = self.content_object.get_email() if email != '': context = {} context['comment_text'] = self.text context['comment_url'] = self.content_object.get_url() text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if self.parent is None: # 评论我的博客 subject = '落叶松的博客:有人评论你的博客' email = self.content_object.get_email() else: # 回复评论 subject = '落叶松的博客:有人回复你的评论' email = self.reply_to.email if email != '': text = '%s\n<a href="localhost:8002%s" >%s</a>' % ( self.text, self.content_object.get_url(), '点击查看') send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if self.parent is None: subject = '有人评论你的博客' email = self.content_object.get_email() else: subject = '有人回复你的评论' email = self.reply_to.email if email != '': context = {} context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render_to_string('comment/send_mail.html', context) send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if self.parent is None: # 评论 subject = '有人评论你的博客' email = self.content_object.get_email() else: # 回复 subject = '有人回复你的评论' email = self.reply_to.email if email != '': text = '%s\n<a href="%s">%s</a>' % ( self.text, self.content_object.get_url(), '查看博客') send_mail = SendMail(subject, text, email) send_mail.start()
def register(request): if request.method == "POST": form = RegisterForm(request.POST) if form.is_valid(): data = form.cleaned_data email = data.get("email") re = User.objects.filter(email=email) if len(re): for u in re: if u.if_use: messages.info(request,"该邮箱已被注册") else: u.delete() passwd = data.get("passwd") hash_pw = make_password(passwd) user = User.objects.create(email=email, passwd=hash_pw) user.save() token = token_confirm.generate_validate_token(email) link = '/'.join([settings.DOMAIN, 'activate', token]) data = {"email": email, "link": link} email_message = loader.render_to_string("re_email.html", data) title = "注册用户验证信息" from_mail = settings.EMAIL_HOST_USER get_mail = [email] send_mail = Send_mail_thread(title, email_message, from_mail, get_mail) send_mail.start() messages.info(request, "欢迎注册,请登录自己的邮箱进行验证") return HttpResponsePermanentRedirect("/Reuser")#用户已存在 else: passwd = data.get("passwd") hash_pw = make_password(passwd) user = User.objects.create(email=email,passwd = hash_pw) user.save() token = token_confirm.generate_validate_token(email) link = '/'.join([settings.DOMAIN,'activate',token]) title = "注册用户验证信息" from_mail = settings.EMAIL_HOST_USER get_mail = [email] data = {"email":email,"link": link} email_message = loader.render_to_string("re_email.html", data) send_mail = Send_mail_thread(title, email_message, from_mail, get_mail) send_mail.start() messages.info(request, "欢迎注册,请登录自己的邮箱进行验证") return HttpResponsePermanentRedirect("/Reuser") else: messages.info(request,"邮箱或者密码格式不正确") return HttpResponsePermanentRedirect("/Reuser")#邮箱或者密码格式不正确 else: return render(request,"404.html")
def send_email(self): if self.parent is None: text = self.comment_content + '\n' + '<a href="' + self.content_object.get_url( ) + '">点击查看</a>' #text=render_to_string('XXXX.html',{'a':1,'b':2}) # text=render(None,'XXXX.html',{'a':1,'b':2}).content.decode('utf-8') email = self.content_object.get_email() send_mail = SendEmail(subject='新的评论', text=text, email=email) send_mail.start() else: text = self.comment_content + '\n' + '<a href="' + self.content_object.get_url( ) + '">点击查看</a>' email = self.content_object.get_email() send_mail = SendEmail(subject='新的回复', text=text, email=email) send_mail.start()
def send_mail_notification(sender, instance, **kwargs): if instance.parent is not None: subject = '你的评论有新的回复', email = instance.reply_to.email else: subject = '你的博客有新评论', email = instance.content_object.author.email if email != '': # text = self.comment_content + self.content_object.get_url() context = {} context['comment_text'] = instance.comment_content context['url'] = instance.content_object.get_url() text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_email(sender, instance, **kwargs): if instance.parent is None: # 评论我的帖子 subject = '有人评论你的帖子' email = instance.content_object.get_email() else: # 回复评论 subject = '有人回复你的评论' email = instance.reply_to.email if email != '': context = {} context['comment_text'] = instance.text context['url'] = instance.content_object.get_url() text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): #发送邮件通知 if self.parent is None:#为评论 subject = '哈喽,有人评论了你的博客~~' email = self.content_object.get_email() else: # 为回复 subject = '哈喽,有人回复了你的评论~~' email = self.reply_to.email if email != '': context = {} context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render_to_string('comment/send_email.html', context) send_mail = SendMail(subject, text, email) # 实例化多线程class send_mail.start() # 开始多线程
def github_check(request): """登录之后,会跳转到这里。需要判断code和state""" request_code = request.GET.get('code') state = request.GET.get('state') or '/' oauth = _get_oauth('Github', state) #获取access_token try: access_token = oauth.get_access_token(request_code) time.sleep(0.05) #稍微休息一下,避免发送urlopen的10060错误 except Exception as e: #登录出错跳转到错误提示页面 return _login_error_response(e, state) #获取用户信息 infos = oauth.get_user_info() open_id = str(infos.get('id', '')) nickname = infos.get('login', '') #检查id是否存在 githubs = OAuth_ex.objects.filter(openid = open_id, oauth_type = oauth.id) #获取邮箱 if githubs: #存在则获取对应的用户,并登录 _login_user(request, githubs[0].user) return HttpResponseRedirect(state) else: #不存在,则尝试获取邮箱 try: #获取得到邮箱则直接绑定 email = oauth.get_email() except Exception as e: #获取不到即跳转到绑定用户 return _bind_email_response(open_id, nickname, oauth.type_name, state) #获取到邮箱,直接绑定 #判断是否存在对应的用户(我这里的用户名就是邮箱,根据你的实际情况参考) user,password = _get_account_from_email(oauth.id, email, open_id, nickname) #登录并跳转 _login_user(request, user) text='这是为您生成的随机密码:%s ,请尽快到个人中心修改' % password send_mail = SendMail('欢迎您成功登陆J.liu的博客', text, user.email) send_mail.start() return _bind_success_response(oauth.state)
def send_mail(self): if self.parent is None: # 评论我的文章 subject = '文章有新评论啦~,请及时查收!' email = self.content_object.get_email() else: # 回复评论 subject = '评论有新回复啦~,请及时查收!' email = self.reply_to.email if email != '': context = {} context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if self.parent is None: # 评论我的博客 subject = '有人评论你的博客' email = self.content_object.author.email else: # 回复评论 subject = '有人回复你的评论' email = self.reply_to.email if email != '': context = {} context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render(None, 'send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if self.parent is None: # 评论我的博客 subject = '博客评论通知' email = self.content_object.get_email() else: # 评论回复 subject = '有人回复你的评论' email = self.reply_to.email if email != "": context = {} context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render(None, 'blog/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_email(self): # 发送邮件通知 if self.parent is None: # 评论我的博客 subject = '有人评论你的博客' email = self.content_object.get_email() else: subject = '有人回复你的评论' email = self.reply_to.email if email != '': text = '%s\n<a href="%s">%s</a>' % (self.text, self.content_object.get_url(), '点击查看') context ={} context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render_to_string('comment/send_mail.html', context) send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): # 发送邮件通知 content = {} if self.parent is None: # 评论博客 subject = '有人评论了你的博客' email = self.content_object.get_email() else: # 回复评论 subject = '有人回复了你的评论' email = self.reply_to.email if email != '': content['comment_text'] = self.text content['url'] = self.content_object.get_url() text = render_to_string('send_email.html', content) send_mail = Sendmail(subject, text, email, False) send_mail.start()
def send_mail(self): # 发送邮件通知 if self.parent is None: # 评论我的头条 subject = '汉海科技消息提示' email = self.content_object.get_email() else: #回复评论 subject = '有人回复你的评论' email = self.reply_to.email if email != '': context = {} context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if self.parent is None: # 评论我的博客 subject = 'byack-笔记(查收你的消息了)' email = self.content_object.get_email() else: # 回复评论 subject = 'byack-笔记(你的评论有回复了)' email = self.reply_to.email if email != '': context = {} context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): # 发送邮件通知 if self.parent is None: # 评论我的博客 subject = '有人评论你的博客' email = self.content_object.get_email() else: # 回复评论 subject = '有人回复你的评论' email = self.reply_to.email if email != '': context = {} context['comment_text'] = self.text text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') text = '%s\n <a href="http://localhost:8000">%s</a>' % (self.text, '点击查看') send_mail = SendMail(subject, text, email) send_mail.start()
def send_emial(self): if self.parent is None: #评论我的博客 subject = '有人评论我的博客' email = self.content_object.get_email() else: #回复评论 subject = '有人回复你的评论' email = self.reply_to.email if email != '': context = { 'comment_text': self.text, 'url': self.content_object.get_url() } text = render_to_string('comment/send_email.html', context=context) send_mail = SendEmail(subject, text, email) #运用多线程 send_mail.start()
def send_mail(self): # 发送邮件通知 context = {} if not self.parent: # 评论我的博客 subject = '有人评论你的博客' email = self.content_object.get_email() else: # 回复评论 subject = '有人回复你的评论' email = self.reply_to.email if email: context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render_to_string('comment/send_mail.html', context) send_mail = SendMail(subject, text, email) send_mail.start()
def send_email(sender, instance, **kwargs): # 发送邮件通知 if instance.parent is None: # 评论我的博客 subject = '有人评论你的博客' email = instance.content_object.get_email() else: # 回复评论 subject = '有人回复你的评论' email = instance.reply_to.email if email != '': context = {} context['comment_text'] = instance.text context['url'] = instance.content_object.get_url() text = render_to_string('comment/send_mail.html', context) send_mail = SendMail(subject, text, email) send_mail.start()
def send_email(sender,instance,**kwargs): # 发送邮件通知 if instance.parent is None: # 评论我的博客 subject = '有人评论你的博客' email = instance.content_object.get_email() else: subject = '有人回复你的评论' email = instance.reply_to.email if email != '': text = '%s\n<a href="%s">%s</a>' % (instance.text, instance.content_object.get_url(), '点击查看') context = {} context['comment_text'] = instance.text context['url'] = instance.content_object.get_url() text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if self.parent is None: # 评论我的item subject = 'Lost&Found 失物提醒邮件' email = self.content_object.get_mail() # print('email ok') else: # 回复评论 return if email != '': # 测试用逻辑,实际不会出现空值 context = {} context['comment_text'] = self.text # context['url'] = self.content_object.get_url() text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if comment.parent is None: # 评论我的博客 subject = '有人评论你的博客' email = comment.content_object.get_email() else: # 回复评论 subject = '有人回复了你的评论' email = comment.reply_to.email if email != '': # text = ' %s\n<a href="%s">%s</a>' %(comment.text, comment.content_object.get_url(), '点击查看') context = {} context['comment_text'] = comment.text context['url'] = comment.content_object.get_url() text = render_to_string('comment/send_mail.html', context) send_mail = SendMail(subject, text, email) # send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if self.parent is None: # 判断评论是否有parent,没有表示是一级评论 # 评论博客,发送邮件 subject = '有人评论你的博客' # 主题 email = self.content_object.get_email() # 评论博客的email else: # 回复评论 subject = '有人回复你的评论' # 主题 email = self.reply_to.email # 评论的email if email != '': # text = self.text + '\n' + self.content_object.get_url() # 评论内容 + 通过comment.content_object(具体评论的对象)获得url context = {} # 给魔法页面传入内容 context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) # 参数传给多线程 send_mail.start() # 开始多线程
def send_mail(self): if self.parent is None: #评论 subject = '有人评论你的博客' email = self.content_object.get_email() else: #回复评论 subject = '有人回复你的评论' email = self.reply_to.email if email != '': # text='%s\n<a href="%s">%s</a>' %s (self.text, self.content_object.get_url(), '点击查看') context = {} context['comment_text'] = self.text context['url'] = self.content_object.get_url() text = render(None, 'comment/send_mail.html', context).content.decode('utf-8') send_mail = SendMail(subject, text, email) send_mail.start()
def send_mail(self): if self.parent is None: # 评论博客 subject = '有人评论你的博客' email = self.content_object.get_email() else: # 回复评论 subject = '有人回复你的评论' email = self.reply_to.email if email != '': context = { 'comment_text': self.text, 'url': self.content_object.get_url(), } text = render_to_string('comment/send_mail.html', context) sender = settings.EMAIL_HOST_USER send_mail = SendMail(subject, text, sender, email) send_mail.start()