Beispiel #1
0
def mail_welcome(user):
  params = {'user':user}
  message = mail.get_mail_message('mail_welcome.txt', **params)
  html_message = mail.get_mail_message('mail_welcome.html', **params)

  subject = "Welcome to %s" % ConfigData.get_configdata('SITE_NAME')
  mail.send_mail(user.email, subject, message, html_message=html_message)
Beispiel #2
0
def email_contact(name, email, message):
  params = {'name':name, 'email':email, 'message':message}
  message = mail.get_mail_message('mail_contact.txt', **params)
  html_message = mail.get_mail_message('mail_contact.html', **params)
  
  subject = "Contact: %s (%s)" % (name, email)
  for to_mail in ContactMessage.get_mails():
    mail.send_mail(to_mail, subject, message, html_message=html_message)
Beispiel #3
0
def mail_password_instructions(user, code):
  _link = "http://%s%s" % (settings.DOMAIN, reverse("users_passwordreset", args=[code]))
  params = {'user':user, "link": _link}
  message = mail.get_mail_message('mail_password_instructions.txt', **params)
  html_message = mail.get_mail_message('mail_password_instructions.html', **params)

  subject = "Reset your %s password" % settings.SITE_NAME

  mail.send_mail(user.email, subject, message, html_message=html_message)
Beispiel #4
0
def mail_confirm(user, mail):
  _link = "http://%s%s" % (settings.DOMAIN, reverse("users_validate_email", args=[code]))
  params = {'user':user, "link": _link}
  message = mail.get_mail_message('mail_validate_email.txt', **params)
  html_message = mail.get_mail_message('mail_validate_email.html', **params)

  subject = "Confirm your %s account" % ConfigData.get_configdata('SITE_NAME')
  
  mail.send_mail(user.email, subject, message, html_message=html_message)
def send_mail(request, key):
  logging.info("**** common.common_views.send_mail")
  if key == settings.TASKS_KEY and request.method == 'POST':
    _mail = request.POST.get("mail")
    subject = request.POST.get("subject")
    message = request.POST.get("message")
    html_message = request.POST.get("html_message")
    mail.send_mail(_mail, subject, message, html_message=html_message)
    return http.HttpResponse('success')
  return http.HttpResponse('error', status=500)
Beispiel #6
0
    def form_valid(self, form):
        email = form.cleaned_data.get("update_email")
        if email:
            # Token doesn't need to be log, not used for signing, just in the user session
            session_token = self.request.session["update_email_token"] = secrets.token_urlsafe(12)
            token = signing.dumps(
                [self.request.user.id, session_token, email],
                salt="update:email",
                compress=True,
            )
            url = self.request.build_absolute_uri(reverse("profile_email_update", kwargs={"token": token}))

            if send_mail(
                email,
                f"Verify Email Address on {config.STATION_NAME}",
                f"Please go to the following URL to verify your email address: {url}",
                request=self.request,
            ):
                messages.warning(
                    self.request,
                    f"A verification email was sent to {email}. To complete your email "
                    "address update, please open it and follow the verification link. If you don't "
                    "receive an email, make sure you've entered the address correctly, and check your "
                    "spam folder.",
                )

        return super().form_valid(form)
Beispiel #7
0
def send_set_password_email(request, user, newly_created=True):
    cache_token = secrets.token_urlsafe(
        12)  # It's signed, so doesn't need to be a very secure token
    # (<user id>, <newly created>, <cache_token>)
    # These links will function good for 12 hours (the duration of the cache key), at which point the user
    # will need to regenerate a new link in their inbox
    # The whole link itself is good for 14 days (or until it's used)
    cache.set(
        f"{constants.CACHE_KEY_SET_PASSWORD_PREFIX}{cache_token}:usable",
        True,
        timeout=12 * 60 * 60,
    )
    cache.set(
        f"{constants.CACHE_KEY_SET_PASSWORD_PREFIX}{cache_token}:valid",
        True,
        timeout=14 * 24 * 60 * 60,
    )
    token = signing.dumps([user.id, newly_created, cache_token],
                          salt="set:password",
                          compress=True)
    url = request.build_absolute_uri(
        reverse("password_set_by_email", kwargs={"token": token}))

    if newly_created:
        subject = f"Welcome to {config.STATION_NAME}!"
        body = (
            f"Congratulations you've got a new account with {config.STATION_NAME}!\n\nThe username for the"
            f" account is: {user.username}\n\nTo set your password please go to the following URL: {url}"
        )
    else:
        subject = f"Change Your Password on {config.STATION_NAME}"
        body = (
            f"To set a password for your account, please go to the following URL: {url}\n\nIn case you've "
            f"forgotten, the username for the account is: {user.username}")

    return send_mail(user.email, subject, body, request=request)
Beispiel #8
0
# coding:utf-8
from common.case import *
from common import mail
from common import report
from config import readConfig
import os

if __name__ == "__main__":
    all_case = add_case()
    report_abs_path = run_case(all_case)
    report_name = os.path.basename(report_abs_path)
    latest_report = report.get_latest_report(os.path.dirname(report_abs_path))
    t = readConfig.get_mail_cfg()
    mail.send_mail(t[0], t[1], t[2], t[3], t[4], latest_report)