def send_reminder_to_nominee(nominee_position): today = datetime.date.today().strftime('%Y%m%d') subject = 'IETF Nomination Information' from_email = settings.NOMCOM_FROM_EMAIL domain = Site.objects.get_current().domain position = nominee_position.position nomcom = position.nomcom nomcom_template_path = '/nomcom/%s/' % nomcom.group.acronym mail_path = nomcom_template_path + NOMINEE_REMINDER_TEMPLATE nominee = nominee_position.nominee to_email = nominee.email.address hash = get_hash_nominee_position(today, nominee_position.id) accept_url = reverse('nomcom_process_nomination_status', None, args=(get_year_by_nomcom(nomcom), nominee_position.id, 'accepted', today, hash)) decline_url = reverse('nomcom_process_nomination_status', None, args=(get_year_by_nomcom(nomcom), nominee_position.id, 'declined', today, hash)) context = { 'nominee': nominee, 'position': position, 'domain': domain, 'accept_url': accept_url, 'decline_url': decline_url } body = render_to_string(mail_path, context) path = '%s%d/%s' % (nomcom_template_path, position.id, QUESTIONNAIRE_TEMPLATE) body += '\n\n%s' % render_to_string(path, context) send_mail_text(None, to_email, from_email, subject, body)
def notify_pending_by_email(request, liaison, fake): # Broken: this does not find the list of approvers for the sending body # For now, we are sending to [email protected] so the Secretariat can nudge # Bug 880: http://trac.tools.ietf.org/tools/ietfdb/ticket/880 # # from ietf.liaisons.utils import IETFHM # # from_entity = IETFHM.get_entity_by_key(liaison.from_raw_code) # if not from_entity: # return None # to_email = [] # for person in from_entity.can_approve(): # to_email.append('%s <%s>' % person.email()) subject = u'New Liaison Statement, "%s" needs your approval' % ( liaison.title) from_email = settings.LIAISON_UNIVERSAL_FROM body = render_to_string( 'liaisons/pending_liaison_mail.txt', dict( liaison=liaison, url=settings.IDTRACKER_BASE_URL + urlreverse( "liaison_approval_detail", kwargs=dict(object_id=liaison.pk)), referenced_url=settings.IDTRACKER_BASE_URL + urlreverse( "liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None, )) # send_mail_text(request, to_email, from_email, subject, body) send_mail_text(request, ['*****@*****.**'], from_email, subject, body)
def send_sdo_reminder(sdo): roles = Role.objects.filter(name="liaiman", group=sdo) if not roles: # no manager to contact return None manager_role = roles[0] subject = 'Request for update of list of authorized individuals' (to_email, cc) = gather_address_lists('liaison_manager_update_request', group=sdo) name = manager_role.person.plain_name() authorized_list = Role.objects.filter( group=sdo, name='auth').select_related("person").distinct() body = render_to_string( 'liaisons/sdo_reminder.txt', dict( manager_name=name, sdo_name=sdo.name, individuals=authorized_list, )) send_mail_text(None, to_email, settings.LIAISON_UNIVERSAL_FROM, subject, body, cc=cc) return body
def send_liaison_by_email(request, liaison, fake=False): if liaison.is_pending( ): # this conditional should definitely be at the caller, not here return notify_pending_by_email(request, liaison, fake) subject = u'New Liaison Statement, "%s"' % (liaison.title) from_email = settings.LIAISON_UNIVERSAL_FROM to_email = liaison.to_poc.split(',') cc = liaison.cc1.split(',') if liaison.technical_contact: cc += liaison.technical_contact.split(',') if liaison.response_contact: cc += liaison.response_contact.split(',') bcc = ['*****@*****.**'] body = render_to_string( 'liaisons/liaison_mail.txt', dict( liaison=liaison, url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.pk)), referenced_url=settings.IDTRACKER_BASE_URL + urlreverse( "liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None, )) send_mail_text(request, to_email, from_email, subject, body, cc=", ".join(cc), bcc=", ".join(bcc))
def email_personnel_change(request, group, text, changed_personnel): (to, cc) = gather_address_lists('group_personnel_change', group=group, changed_personnel=changed_personnel) full_subject = u"Personnel change for %s %s" % (group.acronym, group.type.name) send_mail_text(request, to, None, full_subject, text, cc=cc)
def send_scheduled_message_from_send_queue(send_queue): message = send_queue.message # for some reason, the old Perl code base substituted away . on line starts body = first_dot_on_line_re.sub("", message.body) extra = {} if message.reply_to: extra['Reply-To'] = message.reply_to # announcement.content_type can contain a case-sensitive parts separator, # so we need to keep it as is, not lowercased, but we want a lowercased # version for the coming comparisons. content_type_lowercase = message.content_type.lower() if not content_type_lowercase or 'text/plain' in content_type_lowercase: send_mail_text(None, message.to, message.frm, message.subject, body, cc=message.cc, bcc=message.bcc) elif 'multipart' in content_type_lowercase: # make body a real message so we can parse it body = ("MIME-Version: 1.0\r\nContent-Type: %s\r\n" % message.content_type) + body msg = email.message_from_string(body.encode("utf-8")) send_mail_mime(None, message.to, message.frm, message.subject, msg, cc=message.cc, bcc=message.bcc) send_queue.sent_at = datetime.datetime.now() send_queue.save()
def possibly_send_deadline_reminder(liaison): PREVIOUS_DAYS = { 14: 'in two weeks', 7: 'in one week', 4: 'in four days', 3: 'in three days', 2: 'in two days', 1: 'tomorrow', 0: 'today' } days_to_go = (liaison.deadline - datetime.date.today()).days if not (days_to_go < 0 or days_to_go in PREVIOUS_DAYS.keys()): return None # no reminder if days_to_go < 0: subject = '[Liaison OUT OF DATE] %s' % liaison.title days_msg = 'is out of date for %s days' % (-days_to_go) else: subject = '[Liaison deadline %s] %s' % (PREVIOUS_DAYS[days_to_go], liaison.title) days_msg = 'expires %s' % PREVIOUS_DAYS[days_to_go] from_email = settings.LIAISON_UNIVERSAL_FROM (to_email, cc) = gather_address_lists('liaison_deadline_soon',liaison=liaison) bcc = '*****@*****.**' body = render_to_string('liaisons/liaison_deadline_mail.txt', dict(liaison=liaison,days_msg=days_msg,)) send_mail_text(None, to_email, from_email, subject, body, cc=cc, bcc=bcc) return body
def send_notifications(post_data, ipr_id, update=False): for field in post_data: if 'notify' in field: str_msg = re.sub(r'\r', '', post_data[field]) msg_lines = str_msg.split('\n') body = '\n'.join(msg_lines[4:]) headers = msg_lines[:4] to = re.sub('To:', '', headers[0]).strip() frm = re.sub('From:', '', headers[1]).strip() subject = re.sub('Subject:', '', headers[2]).strip() cc = re.sub('Cc:', '', headers[3]).strip() ''' not required, send_mail_text handles this try: if settings.DEVELOPMENT: to = cc = settings.TEST_EMAIL frm = '*****@*****.**' except AttributeError: pass ''' try: send_mail_text(None, to, frm, subject, body, cc) except (ImproperlyConfigured, SMTPException) as e: return e now = datetime.now() IprNotification(ipr_id=ipr_id, notification=str_msg, date_sent=now.date(), time_sent=now.time()) if update: ipr_dtl = IprDetail.objects.get(ipr_id=ipr_id) today = datetime.today().date() ipr_dtl.update_notified_date = today ipr_dtl.save() return None
def wrap_up_email(to, text): text = wrap(strip_tags(text), 70) text += "\n\n" text += u"URL: %s" % (settings.IDTRACKER_BASE_URL + group.about_url()) send_mail_text(request, to, None, u"Milestones changed for %s %s" % (group.acronym, group.type.name), text)
def send_liaison_by_email(request, liaison): subject = u'New Liaison Statement, "%s"' % (liaison.title) from_email = settings.LIAISON_UNIVERSAL_FROM (to_email, cc) = gather_address_lists('liaison_statement_posted',liaison=liaison) bcc = ['*****@*****.**'] body = render_to_string('liaisons/liaison_mail.txt', dict(liaison=liaison)) send_mail_text(request, to_email, from_email, subject, body, cc=", ".join(cc), bcc=", ".join(bcc))
def notify_pending_by_email(request, liaison): '''Send mail requesting approval of pending liaison statement. Send mail to the intersection of approvers for all from_groups ''' subject = u'New Liaison Statement, "%s" needs your approval' % (liaison.title) from_email = settings.LIAISON_UNIVERSAL_FROM (to, cc) = gather_address_lists('liaison_approval_requested',liaison=liaison) body = render_to_string('liaisons/pending_liaison_mail.txt', dict(liaison=liaison)) send_mail_text(request, to, from_email, subject, body, cc=cc)
def wrap_up_email(to, text): text = wrap(strip_tags(text), 70) text += "\n\n" text += u"URL: %s" % (settings.IDTRACKER_BASE_URL + urlreverse( "wg_charter", kwargs=dict(acronym=group.acronym))) send_mail_text( request, to, None, u"Milestones changed for %s %s" % (group.acronym, group.type.name), text)
def wrap_up_email(addrs, text): subject = u"Milestones changed for %s %s" % (group.acronym, group.type.name) if re.search("Added .* for review, due",text): subject = u"Review Required - " + subject text = wrap(strip_tags(text), 70) text += "\n\n" text += u"URL: %s" % (settings.IDTRACKER_BASE_URL + group.about_url()) send_mail_text(request, addrs.to, None, subject, text, cc=addrs.cc)
def email_state_changed(request, doc, text): to = [e.strip() for e in doc.notify.replace(';', ',').split(',')] if not to: return text = strip_tags(text) text += "\n\n" text += "URL: %s" % (settings.IDTRACKER_BASE_URL + doc.get_absolute_url()) send_mail_text(request, to, None, "State changed: %s-%s" % (doc.canonical_name(), doc.rev), text)
def wrap_up_email(addrs, text): subject = u"Milestones changed for %s %s" % (group.acronym, group.type.name) if re.search("Added .* for review, due", text): subject = u"Review Required - " + subject text = wordwrap(strip_tags(text), 78) text += "\n\n" text += u"URL: %s" % (settings.IDTRACKER_BASE_URL + group.about_url()) send_mail_text(request, addrs.to, None, subject, text, cc=addrs.cc)
def notify_pending_by_email(request, liaison): '''Send mail requesting approval of pending liaison statement. Send mail to the intersection of approvers for all from_groups ''' subject = u'New Liaison Statement, "%s" needs your approval' % ( liaison.title) from_email = settings.LIAISON_UNIVERSAL_FROM (to, cc) = gather_address_lists('liaison_approval_requested', liaison=liaison) body = render_to_string('liaisons/pending_liaison_mail.txt', dict(liaison=liaison)) send_mail_text(request, to, from_email, subject, body, cc=cc)
def email_iana(request, doc, to, msg): # fix up message and send it with extra info on doc in headers import email parsed_msg = email.message_from_string(msg.encode("utf-8")) extra = {} extra["Reply-To"] = "*****@*****.**" extra["X-IETF-Draft-string"] = doc.name extra["X-IETF-Draft-revision"] = doc.rev send_mail_text(request, "IANA <%s>" % to, parsed_msg["From"], parsed_msg["Subject"], parsed_msg.get_payload(), extra=extra)
def send_liaison_by_email(request, liaison): subject = u'New Liaison Statement, "%s"' % (liaison.title) from_email = settings.LIAISON_UNIVERSAL_FROM (to_email, cc) = gather_address_lists('liaison_statement_posted', liaison=liaison) bcc = ['*****@*****.**'] body = render_to_string('liaisons/liaison_mail.txt', dict(liaison=liaison)) send_mail_text(request, to_email, from_email, subject, body, cc=", ".join(cc), bcc=", ".join(bcc))
def send_liaison_by_email(request, liaison): subject = u'New Liaison Statement, "%s"' % (liaison.title) from_email = settings.LIAISON_UNIVERSAL_FROM to_email = liaison.to_contact.split(',') cc = liaison.cc.split(',') if liaison.technical_contact: cc += liaison.technical_contact.split(',') if liaison.response_contact: cc += liaison.response_contact.split(',') bcc = ['*****@*****.**'] body = render_to_string('liaisons/liaison_mail.txt', dict( liaison=liaison, url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.pk)), referenced_url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None, )) send_mail_text(request, to_email, from_email, subject, body, cc=", ".join(cc), bcc=", ".join(bcc))
def notify_pending_by_email(self, fake): from ietf.liaisons.utils import IETFHM from_entity = IETFHM.get_entity_by_key(self.from_raw_code) if not from_entity: return None to_email = [] for person in from_entity.can_approve(): to_email.append('%s <%s>' % person.email()) subject = 'New Liaison Statement, "%s" needs your approval' % (self.title) from_email = settings.LIAISON_UNIVERSAL_FROM body = render_to_string('liaisons/pending_liaison_mail.txt', { 'liaison': self, 'url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_approval_detail", kwargs=dict(object_id=self.pk)), 'referenced_url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=self.related_to.pk)) if self.related_to else None, }) send_mail_text(context=None, to=to_email, frm=from_email, subject=subject, txt = body)
def possibly_send_deadline_reminder(liaison): PREVIOUS_DAYS = { 14: 'in two weeks', 7: 'in one week', 4: 'in four days', 3: 'in three days', 2: 'in two days', 1: 'tomorrow', 0: 'today' } days_to_go = (liaison.deadline - datetime.date.today()).days if not (days_to_go < 0 or days_to_go in PREVIOUS_DAYS.keys()): return None # no reminder if days_to_go < 0: subject = '[Liaison OUT OF DATE] %s' % liaison.title days_msg = 'is out of date for %s days' % (-days_to_go) else: subject = '[Liaison deadline %s] %s' % (PREVIOUS_DAYS[days_to_go], liaison.title) days_msg = 'expires %s' % PREVIOUS_DAYS[days_to_go] from_email = settings.LIAISON_UNIVERSAL_FROM to_email = liaison.to_contact.split(',') cc = liaison.cc.split(',') if liaison.technical_contact: cc += liaison.technical_contact.split(',') if liaison.response_contact: cc += liaison.response_contact.split(',') bcc = '*****@*****.**' body = render_to_string( 'liaisons/liaison_deadline_mail.txt', dict( liaison=liaison, days_msg=days_msg, url=settings.IDTRACKER_BASE_URL + urlreverse( "liaison_approval_detail", kwargs=dict(object_id=liaison.pk)), referenced_url=settings.IDTRACKER_BASE_URL + urlreverse( "liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None, )) send_mail_text(None, to_email, from_email, subject, body, cc=cc, bcc=bcc) return body
def activate_draft_email(apps, schema_editor): Document = apps.get_model("doc", "Document") change_count = 0 notify_user_count = 0 for doc in Document.objects.filter( type__slug='draft', states__slug='active').order_by('-time'): for email in doc.authors.all(): if email.active == False: person = email.person primary = person.email_set.filter( active=True).order_by('-time').first() email.active = True email.save() change_count += 1 # If there isn't a primary address, ther's no active # addresses, and it can't be other than right to change the # draft email address to active. Otherwise, notify the owner. if primary: notify_user_count += 1 primary_email = primary.address inactive_email = email.address if settings.SERVER_MODE == 'production': context = dict( primary_email=primary_email, inactive_email=inactive_email, draft_name=doc.name, ) send_mail_text( request=None, to=[primary_email, inactive_email], frm="Henrik Levkowetz <*****@*****.**>", subject= "Changed email settings for you in the datatracker", txt=email_template % context, extra={ "Reply-To": "Secretariat <*****@*****.**>" }, ) print("") print("Set %s email addresses to active" % change_count) print( "Notified %s users, who had at least one other active email." % notify_user_count)
def send_by_email(self, fake=False): if self.is_pending(): return self.notify_pending_by_email(fake) subject = 'New Liaison Statement, "%s"' % (self.title) from_email = settings.LIAISON_UNIVERSAL_FROM to_email = self.to_poc.split(',') cc = self.cc1.split(',') if self.technical_contact: cc += self.technical_contact.split(',') if self.response_contact: cc += self.response_contact.split(',') bcc = ['*****@*****.**'] body = render_to_string('liaisons/liaison_mail.txt', { 'liaison': self, 'url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=self.pk)), 'referenced_url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=self.related_to.pk)) if self.related_to else None, }) send_mail_text(context=None,to=to_email,frm=from_email,subject=subject,txt=body,cc=cc,bcc=bcc)
def send_email(self, to_email, template): if self.shepherd: subject = 'WG shepherd needs system credentials' else: subject = 'WG Delegate needs system credentials' if settings.USE_DB_REDESIGN_PROXY_CLASSES: persons = Person.objects.filter(email__address=self.email).distinct() else: persons = PersonOrOrgInfo.objects.filter(emailaddress__address=self.email).distinct() body = render_to_string(template, {'chair': get_person_for_user(self.user), 'delegate_email': self.email, 'shepherd': self.shepherd, 'delegate_persons': persons, 'wg': self.wg, }) send_mail_text(self.request, to_email, settings.DEFAULT_FROM_EMAIL, subject, body)
def send_sdo_reminder(sdo): roles = Role.objects.filter(name="liaiman", group=sdo) if not roles: # no manager to contact return None manager_role = roles[0] subject = 'Request for update of list of authorized individuals' (to_email,cc) = gather_address_lists('liaison_manager_update_request',group=sdo) name = manager_role.person.plain_name() authorized_list = Role.objects.filter(group=sdo, name='auth').select_related("person").distinct() body = render_to_string('liaisons/sdo_reminder.txt', dict( manager_name=name, sdo_name=sdo.name, individuals=authorized_list, )) send_mail_text(None, to_email, settings.LIAISON_UNIVERSAL_FROM, subject, body, cc=cc) return body
def email_iana(request, doc, to, msg, cc=None): # fix up message and send it with extra info on doc in headers import email parsed_msg = email.message_from_string(msg.encode("utf-8")) parsed_msg.set_charset('UTF-8') extra = {} extra["Reply-To"] = "*****@*****.**" extra["X-IETF-Draft-string"] = doc.name extra["X-IETF-Draft-revision"] = doc.rev send_mail_text(request, to, parsed_msg["From"], parsed_msg["Subject"], parsed_msg.get_payload().decode( str(parsed_msg.get_charset())), extra=extra, cc=cc)
def send_liaison_by_email(request, liaison, fake=False): if liaison.is_pending(): # this conditional should definitely be at the caller, not here return notify_pending_by_email(request, liaison, fake) subject = u'New Liaison Statement, "%s"' % (liaison.title) from_email = settings.LIAISON_UNIVERSAL_FROM to_email = liaison.to_poc.split(',') cc = liaison.cc1.split(',') if liaison.technical_contact: cc += liaison.technical_contact.split(',') if liaison.response_contact: cc += liaison.response_contact.split(',') bcc = ['*****@*****.**'] body = render_to_string('liaisons/liaison_mail.txt', dict( liaison=liaison, url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.pk)), referenced_url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None, )) send_mail_text(request, to_email, from_email, subject, body, cc=", ".join(cc), bcc=", ".join(bcc))
def send_sdo_reminder(sdo): roles = Role.objects.filter(name="liaiman", group=sdo) if not roles: # no manager to contact return None manager_role = roles[0] subject = 'Request for update of list of authorized individuals' to_email = manager_role.email.address name = manager_role.person.plain_name() authorized_list = role_persons_with_fixed_email(sdo, "auth") body = render_to_string('liaisons/sdo_reminder.txt', dict( manager_name=name, sdo_name=sdo.name, individuals=authorized_list, )) send_mail_text(None, to_email, settings.LIAISON_UNIVERSAL_FROM, subject, body) return body
def confirm(request): # testing #assert False, (request.session.get_expiry_age(),request.session.get_expiry_date()) if request.method == 'POST': form = AnnounceForm(request.session['data'],user=request.user) message = form.save(user=request.user,commit=True) send_mail_text(None, message.to, message.frm, message.subject, message.body, cc=message.cc, bcc=message.bcc) # clear session request.session.clear() messages.success(request, 'The announcement was sent.') url = reverse('announcement') return HttpResponseRedirect(url) if request.session.get('data',None): data = request.session['data'] else: messages.error(request, 'No session data. Your session may have expired or cookies are disallowed.') redirect_url = reverse('announcement') return HttpResponseRedirect(redirect_url) if data['to'] == 'Other...': to = ','.join(data['to_custom']) else: to = data['to'] return render_to_response('announcement/confirm.html', { 'message': data, 'to': to}, RequestContext(request, {}), )
def possibly_send_deadline_reminder(liaison): PREVIOUS_DAYS = { 14: 'in two weeks', 7: 'in one week', 4: 'in four days', 3: 'in three days', 2: 'in two days', 1: 'tomorrow', 0: 'today' } days_to_go = (liaison.deadline - datetime.date.today()).days if not (days_to_go < 0 or days_to_go in PREVIOUS_DAYS.keys()): return None # no reminder if days_to_go < 0: subject = '[Liaison OUT OF DATE] %s' % liaison.title days_msg = 'is out of date for %s days' % (-days_to_go) else: subject = '[Liaison deadline %s] %s' % (PREVIOUS_DAYS[days_to_go], liaison.title) days_msg = 'expires %s' % PREVIOUS_DAYS[days_to_go] from_email = settings.LIAISON_UNIVERSAL_FROM to_email = liaison.to_contact.split(',') cc = liaison.cc.split(',') if liaison.technical_contact: cc += liaison.technical_contact.split(',') if liaison.response_contact: cc += liaison.response_contact.split(',') bcc = '*****@*****.**' body = render_to_string('liaisons/liaison_deadline_mail.txt', dict(liaison=liaison, days_msg=days_msg, url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_approval_detail", kwargs=dict(object_id=liaison.pk)), referenced_url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None, )) send_mail_text(None, to_email, from_email, subject, body, cc=cc, bcc=bcc) return body
def send_email(self, to_email, template): if self.shepherd: subject = 'WG shepherd needs system credentials' else: subject = 'WG Delegate needs system credentials' if settings.USE_DB_REDESIGN_PROXY_CLASSES: persons = Person.objects.filter( email__address=self.email).distinct() else: persons = PersonOrOrgInfo.objects.filter( emailaddress__address=self.email).distinct() body = render_to_string( template, { 'chair': get_person_for_user(self.user), 'delegate_email': self.email, 'shepherd': self.shepherd, 'delegate_persons': persons, 'wg': self.wg, }) send_mail_text(self.request, to_email, settings.DEFAULT_FROM_EMAIL, subject, body)
def send_scheduled_announcement(announcement): # for some reason, the old Perl code base substituted away . on line starts body = first_dot_on_line_re.sub("", announcement.body) extra = {} if announcement.replyto: extra['Reply-To'] = announcement.replyto # announcement.content_type can contain a case-sensitive parts separator, # so we need to keep it as is, not lowercased, but we want a lowercased # version for the coming comparisons. content_type_lowercase = announcement.content_type.lower() if not content_type_lowercase or 'text/plain' in content_type_lowercase: send_mail_text(None, announcement.to_val, announcement.from_val, announcement.subject, body, cc=announcement.cc_val, bcc=announcement.bcc_val) elif 'multipart/' in content_type_lowercase: # make body a real message so we can parse it. body = ("MIME-Version: 1.0\r\nContent-Type: %s\r\n" % announcement.content_type) + body msg = email.message_from_string(body.encode("utf-8")) send_mail_mime(None, announcement.to_val, announcement.from_val, announcement.subject, msg, cc=announcement.cc_val, bcc=announcement.bcc_val) now = datetime.datetime.now() announcement.actual_sent_date = now.date() announcement.actual_sent_time = str(now.time()) announcement.mail_sent = True announcement.save()
def confirm(request): if not check_access(request.user): return HttpResponseForbidden( 'Restricted to: Secretariat, IAD, or chair of IETF, IAB, RSOC, RSE, IAOC, ISOC, NomCom.' ) if request.method == 'POST': form = AnnounceForm(request.POST, user=request.user) if request.method == 'POST': message = form.save(user=request.user, commit=True) extra = {'Reply-To': message.reply_to} send_mail_text(None, message.to, message.frm, message.subject, message.body, cc=message.cc, bcc=message.bcc, extra=extra) messages.success(request, 'The announcement was sent.') return redirect('ietf.secr.announcement.views.main')
def send_questionnaire_reminder_to_nominee(nominee_position): subject = 'Reminder: please complete the Nomcom questionnaires for your nomination.' domain = Site.objects.get_current().domain position = nominee_position.position nomcom = position.nomcom from_email = settings.NOMCOM_FROM_EMAIL.format(year=nomcom.year()) nomcom_template_path = '/nomcom/%s/' % nomcom.group.acronym mail_path = nomcom_template_path + NOMINEE_QUESTIONNAIRE_REMINDER_TEMPLATE nominee = nominee_position.nominee (to_email, cc) = gather_address_lists('nomcom_questionnaire_reminder', nominee=nominee.email.address) context = { 'nominee': nominee, 'position': position, 'domain': domain, 'year': nomcom.year(), } body = render_to_string(mail_path, context) path = '%s%d/%s' % (nomcom_template_path, position.id, QUESTIONNAIRE_TEMPLATE) body += '\n\n%s' % render_to_string(path, context) send_mail_text(None, to_email, from_email, subject, body, cc=cc)
def notify_pending_by_email(request, liaison, fake): # Broken: this does not find the list of approvers for the sending body # For now, we are sending to [email protected] so the Secretariat can nudge # Bug 880: http://trac.tools.ietf.org/tools/ietfdb/ticket/880 # # from ietf.liaisons.utils import IETFHM # # from_entity = IETFHM.get_entity_by_key(liaison.from_raw_code) # if not from_entity: # return None # to_email = [] # for person in from_entity.can_approve(): # to_email.append('%s <%s>' % person.email()) subject = u'New Liaison Statement, "%s" needs your approval' % (liaison.title) from_email = settings.LIAISON_UNIVERSAL_FROM body = render_to_string('liaisons/pending_liaison_mail.txt', dict( liaison=liaison, url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_approval_detail", kwargs=dict(object_id=liaison.pk)), referenced_url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None, )) # send_mail_text(request, to_email, from_email, subject, body) send_mail_text(request, ['*****@*****.**'], from_email, subject, body)
def send_reminder_to_nominee(nominee_position): today = datetime.date.today().strftime('%Y%m%d') subject = 'IETF Nomination Information' from_email = settings.NOMCOM_FROM_EMAIL domain = Site.objects.get_current().domain position = nominee_position.position nomcom = position.nomcom nomcom_template_path = '/nomcom/%s/' % nomcom.group.acronym mail_path = nomcom_template_path + NOMINEE_REMINDER_TEMPLATE nominee = nominee_position.nominee to_email = nominee.email.address hash = get_hash_nominee_position(today, nominee_position.id) accept_url = reverse('nomcom_process_nomination_status', None, args=(get_year_by_nomcom(nomcom), nominee_position.id, 'accepted', today, hash)) decline_url = reverse('nomcom_process_nomination_status', None, args=(get_year_by_nomcom(nomcom), nominee_position.id, 'declined', today, hash)) context = {'nominee': nominee, 'position': position, 'domain': domain, 'accept_url': accept_url, 'decline_url': decline_url} body = render_to_string(mail_path, context) path = '%s%d/%s' % (nomcom_template_path, position.id, QUESTIONNAIRE_TEMPLATE) body += '\n\n%s' % render_to_string(path, context) send_mail_text(None, to_email, from_email, subject, body)
def confirm(request): if request.method == 'POST': form = AnnounceForm(request.session['data'],user=request.user) message = form.save(user=request.user,commit=True) extra = {'Reply-To':message.reply_to} send_mail_text(None, message.to, message.frm, message.subject, message.body, cc=message.cc, bcc=message.bcc, extra=extra) # clear session clear_non_auth(request.session) messages.success(request, 'The announcement was sent.') return redirect('announcement') if request.session.get('data',None): data = request.session['data'] else: messages.error(request, 'No session data. Your session may have expired or cookies are disallowed.') return redirect('announcement') if data['to'] == 'Other...': to = ','.join(data['to_custom']) else: to = data['to'] return render_to_response('announcement/confirm.html', { 'message': data, 'to': to}, RequestContext(request, {}), )
def send_notifications(post_data, ipr_id, update=False): for field in post_data: if 'notify' in field: str_msg = re.sub(r'\r', '', post_data[field]) msg_lines = str_msg.split('\n') body = '\n'.join(msg_lines[4:]) headers = msg_lines[:4] to = re.sub('To:', '', headers[0]).strip() frm = re.sub('From:', '', headers[1]).strip() subject = re.sub('Subject:', '', headers[2]).strip() cc = re.sub('Cc:', '', headers[3]).strip() ''' not required, send_mail_text handles this try: if settings.DEVELOPMENT: to = cc = settings.TEST_EMAIL frm = '*****@*****.**' except AttributeError: pass ''' try: send_mail_text(None, to, frm, subject, body, cc) except (ImproperlyConfigured, SMTPException) as e: return e now = datetime.now() IprNotification( ipr_id=ipr_id, notification=str_msg, date_sent=now.date(), time_sent=now.time() ) if update: ipr_dtl = IprDetail.objects.get(ipr_id=ipr_id) today = datetime.today().date() ipr_dtl.update_notified_date = today ipr_dtl.save() return None
def activate_draft_email(apps, schema_editor): Document = apps.get_model("doc", "Document") change_count = 0 notify_user_count = 0 for doc in Document.objects.filter(type__slug='draft', states__slug='active').order_by('-time'): for email in doc.authors.all(): if email.active == False: person = email.person primary = person.email_set.filter(active=True).order_by('-time').first() email.active = True email.save() change_count += 1 # If there isn't a primary address, ther's no active # addresses, and it can't be other than right to change the # draft email address to active. Otherwise, notify the owner. if primary: notify_user_count +=1 primary_email = primary.address inactive_email = email.address if settings.SERVER_MODE == 'production': context = dict( primary_email=primary_email, inactive_email=inactive_email, draft_name=doc.name, ) send_mail_text( request=None, to=[ primary_email, inactive_email ], frm="Henrik Levkowetz <*****@*****.**>", subject="Changed email settings for you in the datatracker", txt= email_template % context, extra={"Reply-To": "Secretariat <*****@*****.**>"}, ) print("") print("Set %s email addresses to active" % change_count) print("Notified %s users, who had at least one other active email." % notify_user_count)
def send_sdo_reminder(sdo): roles = Role.objects.filter(name="liaiman", group=sdo) if not roles: # no manager to contact return None manager_role = roles[0] subject = 'Request for update of list of authorized individuals' to_email = manager_role.email.address name = manager_role.person.plain_name() authorized_list = role_persons_with_fixed_email(sdo, "auth") body = render_to_string( 'liaisons/sdo_reminder.txt', dict( manager_name=name, sdo_name=sdo.name, individuals=authorized_list, )) send_mail_text(None, to_email, settings.LIAISON_UNIVERSAL_FROM, subject, body) return body
def possibly_send_deadline_reminder(liaison): PREVIOUS_DAYS = { 14: 'in two weeks', 7: 'in one week', 4: 'in four days', 3: 'in three days', 2: 'in two days', 1: 'tomorrow', 0: 'today' } days_to_go = (liaison.deadline - datetime.date.today()).days if not (days_to_go < 0 or days_to_go in PREVIOUS_DAYS.keys()): return None # no reminder if days_to_go < 0: subject = '[Liaison OUT OF DATE] %s' % liaison.title days_msg = 'is out of date for %s days' % (-days_to_go) else: subject = '[Liaison deadline %s] %s' % (PREVIOUS_DAYS[days_to_go], liaison.title) days_msg = 'expires %s' % PREVIOUS_DAYS[days_to_go] from_email = settings.LIAISON_UNIVERSAL_FROM (to_email, cc) = gather_address_lists('liaison_deadline_soon', liaison=liaison) bcc = '*****@*****.**' body = render_to_string('liaisons/liaison_deadline_mail.txt', dict( liaison=liaison, days_msg=days_msg, )) send_mail_text(None, to_email, from_email, subject, body, cc=cc, bcc=bcc) return body
def send_accept_reminder_to_nominee(nominee_position): today = datetime.date.today().strftime('%Y%m%d') subject = 'Reminder: please accept (or decline) your nomination.' domain = Site.objects.get_current().domain position = nominee_position.position nomcom = position.nomcom from_email = settings.NOMCOM_FROM_EMAIL.format(year=nomcom.year()) nomcom_template_path = '/nomcom/%s/' % nomcom.group.acronym mail_path = nomcom_template_path + NOMINEE_ACCEPT_REMINDER_TEMPLATE nominee = nominee_position.nominee (to_email, cc) = gather_address_lists('nomination_accept_reminder', nominee=nominee.email.address) hash = get_hash_nominee_position(today, nominee_position.id) accept_url = reverse('ietf.nomcom.views.process_nomination_status', None, args=(get_year_by_nomcom(nomcom), nominee_position.id, 'accepted', today, hash)) decline_url = reverse('ietf.nomcom.views.process_nomination_status', None, args=(get_year_by_nomcom(nomcom), nominee_position.id, 'declined', today, hash)) context = { 'nominee': nominee, 'position': position, 'domain': domain, 'accept_url': accept_url, 'decline_url': decline_url, 'year': nomcom.year(), } body = render_to_string(mail_path, context) path = '%s%d/%s' % (nomcom_template_path, position.id, QUESTIONNAIRE_TEMPLATE) body += '\n\n%s' % render_to_string(path, context) send_mail_text(None, to_email, from_email, subject, body, cc=cc)
def send_reminder(self, liaison, days_to_go): if days_to_go < 0: subject = '[Liaison OUT OF DATE] %s' % liaison.title days_msg = 'is out of date for %s days' % (-days_to_go) else: subject = '[Liaison deadline %s] %s' % (PREVIOUS_DAYS[days_to_go], liaison.title) days_msg = 'expires %s' % PREVIOUS_DAYS[days_to_go] from_email = settings.LIAISON_UNIVERSAL_FROM to_email = liaison.to_poc.split(',') cc = liaison.cc1.split(',') if liaison.technical_contact: cc += liaison.technical_contact.split(',') if liaison.response_contact: cc += liaison.response_contact.split(',') bcc = ['*****@*****.**'] body = render_to_string('liaisons/liaison_deadline_mail.txt', {'liaison': liaison, 'days_msg': days_msg, 'url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_approval_detail", kwargs=dict(object_id=liaison.pk)), 'referenced_url': settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None, }) send_mail_text(context=None,to=to_email,frm=from_email,cc=cc,subject=subject,bcc=bcc,txt=body) print 'Liaison %05s#: Deadline reminder Sent!' % liaison.pk
def send_ballot_comment(request, name, ballot_id): """Email document ballot position discuss/comment for Area Director.""" doc = get_object_or_404(Document, docalias__name=name) ballot = get_object_or_404(BallotDocEvent, type="created_ballot", pk=ballot_id, doc=doc) ad = request.user.person if 'ballot_edit_return_point' in request.session: return_to_url = request.session['ballot_edit_return_point'] else: return_to_url = urlreverse("ietf.doc.views_doc.document_ballot", kwargs=dict(name=doc.name, ballot_id=ballot_id)) if 'HTTP_REFERER' in request.META: back_url = request.META['HTTP_REFERER'] else: back_url = urlreverse("ietf.doc.views_doc.document_ballot", kwargs=dict(name=doc.name, ballot_id=ballot_id)) # if we're in the Secretariat, we can select an AD to act as stand-in for if not has_role(request.user, "Area Director"): ad_id = request.GET.get('ad') if not ad_id: raise Http404 ad = get_object_or_404(Person, pk=ad_id) pos = doc.latest_event(BallotPositionDocEvent, type="changed_ballot_position", ad=ad, ballot=ballot) if not pos: raise Http404 subj = [] d = "" blocking_name = "DISCUSS" if pos.pos.blocking and pos.discuss: d = pos.discuss blocking_name = pos.pos.name.upper() subj.append(blocking_name) c = "" if pos.comment: c = pos.comment subj.append("COMMENT") ad_name_genitive = ad.plain_name() + "'" if ad.plain_name().endswith( 's') else ad.plain_name() + "'s" subject = "%s %s on %s" % (ad_name_genitive, pos.pos.name if pos.pos else "No Position", doc.name + "-" + doc.rev) if subj: subject += ": (with %s)" % " and ".join(subj) body = render_to_string( "doc/ballot/ballot_comment_mail.txt", dict(discuss=d, comment=c, ad=ad.plain_name(), doc=doc, pos=pos.pos, blocking_name=blocking_name, settings=settings)) frm = ad.role_email("ad").formatted_email() addrs = gather_address_lists('ballot_saved', doc=doc) if request.method == 'POST': cc = [] cc_select_form = CcSelectForm(data=request.POST, mailtrigger_slug='ballot_saved', mailtrigger_context={'doc': doc}) if cc_select_form.is_valid(): cc.extend(cc_select_form.get_selected_addresses()) extra_cc = [ x.strip() for x in request.POST.get("extra_cc", "").split(',') if x.strip() ] if extra_cc: cc.extend(extra_cc) send_mail_text(request, addrs.to, frm, subject, body, cc=u", ".join(cc)) return HttpResponseRedirect(return_to_url) else: cc_select_form = CcSelectForm(mailtrigger_slug='ballot_saved', mailtrigger_context={'doc': doc}) return render( request, 'doc/ballot/send_ballot_comment.html', dict( doc=doc, subject=subject, body=body, frm=frm, to=addrs.as_strings().to, ad=ad, can_send=d or c, back_url=back_url, cc_select_form=cc_select_form, ))
def get_or_create_nominee(nomcom, candidate_name, candidate_email, position, author): from ietf.nomcom.models import Nominee, NomineePosition nomcom_template_path = '/nomcom/%s/' % nomcom.group.acronym nomcom_chair = nomcom.group.get_chair() nomcom_chair_mail = nomcom_chair and nomcom_chair.email.address or None # Create person and email if candidate email does't exist and send email email, created_email = Email.objects.get_or_create(address=candidate_email) if created_email: email.person = Person.objects.create( name=candidate_name, ascii=unaccent.asciify(candidate_name), address=candidate_email) email.save() # Add the nomination for a particular position nominee, created = Nominee.objects.get_or_create(email=email, nomcom=nomcom) while nominee.duplicated: nominee = nominee.duplicated nominee_position, nominee_position_created = NomineePosition.objects.get_or_create( position=position, nominee=nominee) if created_email: # send email to secretariat and nomcomchair to warn about the new person subject = 'New person is created' from_email = settings.NOMCOM_FROM_EMAIL to_email = [settings.NOMCOM_ADMIN_EMAIL] context = { 'email': email.address, 'fullname': email.person.name, 'person_id': email.person.id } path = nomcom_template_path + INEXISTENT_PERSON_TEMPLATE if nomcom_chair_mail: to_email.append(nomcom_chair_mail) send_mail(None, to_email, from_email, subject, path, context) if nominee_position_created: # send email to nominee subject = 'IETF Nomination Information' from_email = settings.NOMCOM_FROM_EMAIL to_email = email.address domain = Site.objects.get_current().domain today = datetime.date.today().strftime('%Y%m%d') hash = get_hash_nominee_position(today, nominee_position.id) accept_url = reverse('nomcom_process_nomination_status', None, args=(get_year_by_nomcom(nomcom), nominee_position.id, 'accepted', today, hash)) decline_url = reverse('nomcom_process_nomination_status', None, args=(get_year_by_nomcom(nomcom), nominee_position.id, 'declined', today, hash)) context = { 'nominee': email.person.name, 'position': position.name, 'domain': domain, 'accept_url': accept_url, 'decline_url': decline_url } path = nomcom_template_path + NOMINEE_EMAIL_TEMPLATE send_mail(None, to_email, from_email, subject, path, context) # send email to nominee with questionnaire if nomcom.send_questionnaire: subject = '%s Questionnaire' % position from_email = settings.NOMCOM_FROM_EMAIL to_email = email.address context = {'nominee': email.person.name, 'position': position.name} path = '%s%d/%s' % (nomcom_template_path, position.id, HEADER_QUESTIONNAIRE_TEMPLATE) body = render_to_string(path, context) path = '%s%d/%s' % (nomcom_template_path, position.id, QUESTIONNAIRE_TEMPLATE) body += '\n\n%s' % render_to_string(path, context) send_mail_text(None, to_email, from_email, subject, body) # send emails to nomcom chair subject = 'Nomination Information' from_email = settings.NOMCOM_FROM_EMAIL to_email = nomcom_chair_mail context = { 'nominee': email.person.name, 'nominee_email': email.address, 'position': position.name } if author: context.update({ 'nominator': author.person.name, 'nominator_email': author.address }) path = nomcom_template_path + NOMINATION_EMAIL_TEMPLATE send_mail(None, to_email, from_email, subject, path, context) return nominee
def send_simple_mail(to): send_mail_text(None, to=to, frm=None, subject="Test for rejection", txt="dummy body")
def send_ballot_comment(request, name): """Email Internet Draft ballot discuss/comment for area director.""" doc = get_object_or_404(InternetDraft, filename=name) if not doc.idinternal: raise Http404() ad = login = IESGLogin.objects.get(login_name=request.user.username) return_to_url = request.GET.get('return_to_url') if not return_to_url: return_to_url = doc.idinternal.get_absolute_url() if 'HTTP_REFERER' in request.META: back_url = request.META['HTTP_REFERER'] else: back_url = doc.idinternal.get_absolute_url() # if we're in the Secretariat, we can select an AD to act as stand-in for if not in_group(request.user, "Area_Director"): ad_username = request.GET.get('ad') if not ad_username: raise Http404() ad = get_object_or_404(IESGLogin, login_name=ad_username) pos, discuss, comment = get_ballot_info(doc.idinternal.ballot, ad) subj = [] d = "" if pos and pos.discuss == 1 and discuss and discuss.text: d = discuss.text subj.append("DISCUSS") c = "" if comment and comment.text: c = comment.text subj.append("COMMENT") ad_name = str(ad) ad_name_genitive = ad_name + "'" if ad_name.endswith('s') else ad_name + "'s" subject = "%s %s on %s" % (ad_name_genitive, pos.name() if pos else "No Position" , doc.filename + '-' + doc.revision_display()) if subj: subject += ": (with "+" and ".join(subj)+")" body = render_to_string("idrfc/ballot_comment_mail.txt", dict(discuss=d, comment=c, ad=ad, doc=doc, pos=pos, settings=settings)) frm = u"%s <%s>" % ad.person.email() to = "The IESG <*****@*****.**>" if request.method == 'POST': cc = [x.strip() for x in request.POST.get("cc", "").split(',') if x.strip()] if request.POST.get("cc_state_change") and doc.idinternal.state_change_notice_to: cc.extend(doc.idinternal.state_change_notice_to.split(',')) send_mail_text(request, to, frm, subject, body, cc=", ".join(cc)) return HttpResponseRedirect(return_to_url) return render_to_response('idrfc/send_ballot_comment.html', dict(doc=doc, subject=subject, body=body, frm=frm, to=to, ad=ad, can_send=d or c, back_url=back_url, ), context_instance=RequestContext(request))
def email_authors(request, doc, subject, text): to = [x.strip() for x in doc.author_list().split(',')] if not to: return send_mail_text(request, to, None, subject, text)
def email_personnel_change(request, group, text, changed_personnel): (to, cc) = gather_address_lists('group_personnel_change',group=group,changed_personnel=changed_personnel) full_subject = u"Personnel change for %s %s" % (group.acronym,group.type.name) send_mail_text(request, to, None, full_subject, text, cc=cc)
def update_drafts_from_queue(drafts): tag_mapping = { 'IANA': DocTagName.objects.get(slug='iana'), 'REF': DocTagName.objects.get(slug='ref') } slookup = dict((s.slug, s) for s in State.objects.filter(used=True, type=StateType.objects.get(slug="draft-rfceditor"))) state_mapping = { 'AUTH': slookup['auth'], 'AUTH48': slookup['auth48'], 'AUTH48-DONE': slookup['auth48-done'], 'EDIT': slookup['edit'], 'IANA': slookup['iana'], 'IESG': slookup['iesg'], 'ISR': slookup['isr'], 'ISR-AUTH': slookup['isr-auth'], 'REF': slookup['ref'], 'RFC-EDITOR': slookup['rfc-edit'], 'TO': slookup['timeout'], 'MISSREF': slookup['missref'], } system = Person.objects.get(name="(System)") warnings = [] names = [t[0] for t in drafts] drafts_in_db = dict((d.name, d) for d in Document.objects.filter(type="draft", docalias__name__in=names)) changed = set() for name, date_received, state, tags, missref_generation, stream, auth48, cluster, refs in drafts: if name not in drafts_in_db: warnings.append("unknown document %s" % name) continue if not state or state not in state_mapping: warnings.append("unknown state '%s'" % state) continue d = drafts_in_db[name] prev_state = d.get_state("draft-rfceditor") next_state = state_mapping[state] # check if we've noted it's been received if d.get_state_slug("draft-iesg") == "ann" and not prev_state and not d.latest_event(DocEvent, type="rfc_editor_received_announcement"): e = DocEvent(doc=d, by=system, type="rfc_editor_received_announcement") e.desc = "Announcement was received by RFC Editor" e.save() send_mail_text(None, "*****@*****.**", None, '%s in RFC Editor queue' % d.name, 'The announcement for %s has been received by the RFC Editor.' % d.name) if prev_state != next_state: save_document_in_history(d) d.set_state(next_state) e = add_state_change_event(d, system, prev_state, next_state) if auth48: e.desc = re.sub(r"(<b>.*</b>)", "<a href=\"%s\">\\1</a>" % auth48, e.desc) e.save() changed.add(name) t = DocTagName.objects.filter(slug__in=tags) if set(t) != set(d.tags.all()): d.tags = t changed.add(name) # remove tags and states for those not in the queue anymore for d in Document.objects.exclude(docalias__name__in=names).filter(states__type="draft-rfceditor").distinct(): d.tags.remove(*tag_mapping.values()) d.unset_state("draft-rfceditor") # we do not add a history entry here - most likely we already # have something that explains what happened changed.add(name) return changed, warnings
def send_ballot_comment(request, name, ballot_id): """Email document ballot position discuss/comment for Area Director.""" doc = get_object_or_404(Document, docalias__name=name) ballot = get_object_or_404(BallotDocEvent, type="created_ballot", pk=ballot_id, doc=doc) ad = request.user.person return_to_url = request.GET.get('return_to_url') if not return_to_url: return_to_url = urlreverse("doc_ballot", kwargs=dict(name=doc.name, ballot_id=ballot_id)) if 'HTTP_REFERER' in request.META: back_url = request.META['HTTP_REFERER'] else: back_url = urlreverse("doc_ballot", kwargs=dict(name=doc.name, ballot_id=ballot_id)) # if we're in the Secretariat, we can select an AD to act as stand-in for if not has_role(request.user, "Area Director"): ad_id = request.GET.get('ad') if not ad_id: raise Http404() ad = get_object_or_404(Person, pk=ad_id) pos = doc.latest_event(BallotPositionDocEvent, type="changed_ballot_position", ad=ad, ballot=ballot) if not pos: raise Http404() subj = [] d = "" blocking_name = "DISCUSS" if pos.pos.blocking and pos.discuss: d = pos.discuss blocking_name = pos.pos.name.upper() subj.append(blocking_name) c = "" if pos.comment: c = pos.comment subj.append("COMMENT") ad_name_genitive = ad.plain_name() + "'" if ad.plain_name().endswith('s') else ad.plain_name() + "'s" subject = "%s %s on %s" % (ad_name_genitive, pos.pos.name if pos.pos else "No Position", doc.name + "-" + doc.rev) if subj: subject += ": (with %s)" % " and ".join(subj) body = render_to_string("doc/ballot/ballot_comment_mail.txt", dict(discuss=d, comment=c, ad=ad.plain_name(), doc=doc, pos=pos.pos, blocking_name=blocking_name, settings=settings)) frm = ad.role_email("ad").formatted_email() to = "The IESG <*****@*****.**>" if request.method == 'POST': cc = [x.strip() for x in request.POST.get("cc", "").split(',') if x.strip()] if request.POST.get("cc_state_change") and doc.notify: cc.extend(doc.notify.split(',')) send_mail_text(request, to, frm, subject, body, cc=u", ".join(cc)) return HttpResponseRedirect(return_to_url) return render_to_response('doc/ballot/send_ballot_comment.html', dict(doc=doc, subject=subject, body=body, frm=frm, to=to, ad=ad, can_send=d or c, back_url=back_url, ), context_instance=RequestContext(request))
def make_nomineeposition(nomcom, candidate, position, author): from ietf.nomcom.models import Nominee, NomineePosition nomcom_template_path = '/nomcom/%s/' % nomcom.group.acronym # Add the nomination for a particular position nominee, created = Nominee.objects.get_or_create(person=candidate, email=candidate.email(), nomcom=nomcom) while nominee.duplicated: nominee = nominee.duplicated nominee_position, nominee_position_created = NomineePosition.objects.get_or_create( position=position, nominee=nominee) if nominee_position_created: # send email to nominee subject = 'IETF Nomination Information' from_email = settings.NOMCOM_FROM_EMAIL.format(year=nomcom.year()) (to_email, cc) = gather_address_lists('nomination_new_nominee', nominee=nominee.email.address) domain = Site.objects.get_current().domain today = datetime.date.today().strftime('%Y%m%d') hash = get_hash_nominee_position(today, nominee_position.id) accept_url = reverse('ietf.nomcom.views.process_nomination_status', None, args=(nomcom.year(), nominee_position.id, 'accepted', today, hash)) decline_url = reverse('ietf.nomcom.views.process_nomination_status', None, args=(nomcom.year(), nominee_position.id, 'declined', today, hash)) context = { 'nominee': nominee.person.name, 'position': position.name, 'year': nomcom.year(), 'domain': domain, 'accept_url': accept_url, 'decline_url': decline_url, } path = nomcom_template_path + NOMINEE_EMAIL_TEMPLATE send_mail(None, to_email, from_email, subject, path, context, cc=cc) # send email to nominee with questionnaire if nomcom.send_questionnaire: subject = '%s Questionnaire' % position from_email = settings.NOMCOM_FROM_EMAIL.format(year=nomcom.year()) (to_email, cc) = gather_address_lists('nomcom_questionnaire', nominee=nominee.email.address) context = { 'nominee': nominee.person.name, 'position': position.name, 'year': nomcom.year(), } path = '%s%d/%s' % (nomcom_template_path, position.id, HEADER_QUESTIONNAIRE_TEMPLATE) body = render_to_string(path, context) path = '%s%d/%s' % (nomcom_template_path, position.id, QUESTIONNAIRE_TEMPLATE) body += '\n\n%s' % render_to_string(path, context) send_mail_text(None, to_email, from_email, subject, body, cc=cc) # send emails to nomcom chair subject = 'Nomination Information' from_email = settings.NOMCOM_FROM_EMAIL.format(year=nomcom.year()) (to_email, cc) = gather_address_lists('nomination_received', nomcom=nomcom) context = { 'nominee': nominee.person.name, 'nominee_email': nominee.email.address, 'position': position.name, 'year': nomcom.year(), } if author: context.update({ 'nominator': author.person.name, 'nominator_email': author.address }) else: context.update({'nominator': 'Anonymous', 'nominator_email': ''}) path = nomcom_template_path + NOMINATION_EMAIL_TEMPLATE send_mail(None, to_email, from_email, subject, path, context, cc=cc) return nominee
def get_or_create_nominee(nomcom, candidate_name, candidate_email, position, author): from ietf.nomcom.models import Nominee, NomineePosition nomcom_template_path = '/nomcom/%s/' % nomcom.group.acronym nomcom_chair = nomcom.group.get_chair() nomcom_chair_mail = nomcom_chair and nomcom_chair.email.address or None # Create person and email if candidate email does't exist and send email email, created_email = Email.objects.get_or_create(address=candidate_email) if created_email: email.person = Person.objects.create(name=candidate_name, ascii=unaccent.asciify(candidate_name), address=candidate_email) email.save() # Add the nomination for a particular position nominee, created = Nominee.objects.get_or_create(email=email, nomcom=nomcom) while nominee.duplicated: nominee = nominee.duplicated nominee_position, nominee_position_created = NomineePosition.objects.get_or_create(position=position, nominee=nominee) if created_email: # send email to secretariat and nomcomchair to warn about the new person subject = 'New person is created' from_email = settings.NOMCOM_FROM_EMAIL to_email = [settings.NOMCOM_ADMIN_EMAIL] context = {'email': email.address, 'fullname': email.person.name, 'person_id': email.person.id} path = nomcom_template_path + INEXISTENT_PERSON_TEMPLATE if nomcom_chair_mail: to_email.append(nomcom_chair_mail) send_mail(None, to_email, from_email, subject, path, context) if nominee_position_created: # send email to nominee subject = 'IETF Nomination Information' from_email = settings.NOMCOM_FROM_EMAIL to_email = email.address domain = Site.objects.get_current().domain today = datetime.date.today().strftime('%Y%m%d') hash = get_hash_nominee_position(today, nominee_position.id) accept_url = reverse('nomcom_process_nomination_status', None, args=(get_year_by_nomcom(nomcom), nominee_position.id, 'accepted', today, hash)) decline_url = reverse('nomcom_process_nomination_status', None, args=(get_year_by_nomcom(nomcom), nominee_position.id, 'declined', today, hash)) context = {'nominee': email.person.name, 'position': position.name, 'domain': domain, 'accept_url': accept_url, 'decline_url': decline_url} path = nomcom_template_path + NOMINEE_EMAIL_TEMPLATE send_mail(None, to_email, from_email, subject, path, context) # send email to nominee with questionnaire if nomcom.send_questionnaire: subject = '%s Questionnaire' % position from_email = settings.NOMCOM_FROM_EMAIL to_email = email.address context = {'nominee': email.person.name, 'position': position.name} path = '%s%d/%s' % (nomcom_template_path, position.id, HEADER_QUESTIONNAIRE_TEMPLATE) body = render_to_string(path, context) path = '%s%d/%s' % (nomcom_template_path, position.id, QUESTIONNAIRE_TEMPLATE) body += '\n\n%s' % render_to_string(path, context) send_mail_text(None, to_email, from_email, subject, body) # send emails to nomcom chair subject = 'Nomination Information' from_email = settings.NOMCOM_FROM_EMAIL to_email = nomcom_chair_mail context = {'nominee': email.person.name, 'nominee_email': email.address, 'position': position.name} if author: context.update({'nominator': author.person.name, 'nominator_email': author.address}) path = nomcom_template_path + NOMINATION_EMAIL_TEMPLATE send_mail(None, to_email, from_email, subject, path, context) return nominee