def import_send_mail_error(mail_to, file_name, error):
    """
        Send email after export is failed

        .. :quickref: Send email after export is failed


        :query User role: User who runs the export
        :query {} export: Export definition
        :query str error: Detail of the exception raised

    """
    msg = f"""
        Bonjour,
        <p>
            Votre import <i>{file_name}</i> n'a pas fonctionné correctement.
        </p>
        <p> {error} </p>

    """
    send_mail(
        recipients=mail_to,
        subject="[GeoNature][ERREUR] Import {}".format(file_name),
        msg_html=msg,
    )
def import_send_mail(mail_to, file_name, step, id_import):
    """
        Send email after export is done

        .. :quickref: Imports

        Send email after import is done
        :param mail_to: User who runs the import
        :param step: step of the process: 'import' | 'check'
    """
    if step == "check":
        link = f"{current_app.config['URL_APPLICATION']}/#/import/process/id_import/{str(id_import)}/step/4"
        msg = f"""
        Bonjour,
        <p>
            Les vérifications sur le fichier {file_name} sont terminées.
        </p>
        <p>  Cliquez sur ce <a target="_blank" href="{link}"> lien </a>  
        pour terminer l'import dans la synthèse.</p>

        """
    else:
        msg = f"""
        Bonjour,
        <p>
            L'import du fichier {file_name} dans la synthèse est terminé.
        </p>
        """

    send_mail(
        recipients=mail_to,
        subject="[GeoNature] Import réalisé" if
        (step == "import") else "[GeoNature] Import - Contrôles terminés",
        msg_html=msg,
    )
Exemple #3
0
def export_send_admin_mail_error(mail_to, export, error):
    """
        Send email after export has failed

        .. :quickref: Send email after export has failed


        :query [str] role: User who runs the export
        :query {} export: Export definition
        :query str error: Detail of the exception raised

    """

    label = ""
    if export:
        label = export['label']

    msg = """
        Bonjour,
        <p>
            L'export <i>{}</i> n'a pas fonctionné correctement.
        </p>
        <p>
            <b>Detail : </b>
            {}
        </p>
    """.format(label, error)
    send_mail(
        recipients=mail_to,
        subject="[GeoNature-export][ERREUR] Export {}".format(label),
        msg_html=msg
    )
Exemple #4
0
def export_send_mail(role, export, file_name):
    """
        Send email after export is done

        .. :quickref: Send email after export is done


        :query User role: User who run the export
        :query {} export: Export definition
        :query str file_name: Name of exported file
    """
    url = url_for('static', filename='exports/' + file_name)

    msg = """
        Bonjour,
        <p>
            Votre export {} est accessible via le lien suivant
            <a href="{}">Lien de téléchargement</a>
        </p>
        <p>
            Les données de cet export sont associée à la licence <a href="{}">{}</a>.
            Merci de les utiliser en respectant la licence.
        </p>
        <p>
            <b>Attention : Ce fichier sera supprimé sous {} jours</b>
        </p>
    """.format(export['label'], url, export['licence']['url_licence'],
               export['licence']['name_licence'],
               str(current_app.config['EXPORTS']['nb_days_keep_file']))
    send_mail(recipients=[role.email],
              subject="[GeoNature]Export {} réalisé".format(export['label']),
              msg_html=msg)
Exemple #5
0
def export_send_mail_error(role, export, error):
    """
        Send email after export is failed

        .. :quickref: Send email after export is failed


        :query User role: User who run the export
        :query {} export: Export definition
        :query str error: Detail of the exception raised

    """

    label = ""
    if export:
        label = export['label']

    msg = """
        Bonjour,
        <p>
            Votre export {} n'a pas fonctionné correctement
        </p>
        <p>
            <b>Detail</b>
            {}
        </p>
        <p>
            Veuillez signaler le problème à l'administrateur du site
        </p>
    """.format(label, error)
    send_mail(recipients=[role.email],
              subject="[GeoNature][ERREUR]Export {}".format(label),
              msg_html=msg)
Exemple #6
0
def export_send_mail(mail_to, export, file_name):
    """
        Send email after export is done

        .. :quickref: Send email after export is done


        :query [str] mail_to: User who runs the export
        :query {} export: Export definition
        :query str file_name: Name of exported file
    """
    module_conf = current_app.config['EXPORTS']

    if module_conf.get('export_web_url'):
        url = "{}/{}".format(
            module_conf.get('export_web_url'),
            file_name
        )
    else:
        url = url_for(
            'static',
            filename='exports/' + module_conf.get('usr_generated_dirname') + '/' + file_name
        )


    msg = """
            Bonjour,
            <p>
                Votre export <i>{}</i> est accessible via le lien suivant :
                <a href="{}">Téléchargement</a>.
            </p>
            <p>
                Les données de cet export sont associées à la licence <a href="{}">{}</a>.
                Merci de les utiliser en respectant cette licence.
            </p>
            <p>
                <b>Attention</b> : Ce fichier sera supprimé sous {} jours.
            </p>
        """.format(
        export['label'],
        url,
        export['licence']['url_licence'],
        export['licence']['name_licence'],
        str(current_app.config['EXPORTS']['nb_days_keep_file'])
    )

    send_mail(
        recipients=mail_to,
        subject="[GeoNature] Export {} réalisé".format(export['label']),
        msg_html=msg
    )
Exemple #7
0
def export_send_mail_error(mail_to, export, error):
    """
        Send email after export is failed

        .. :quickref: Send email after export is failed


        :query [str] mail_to: User who runs the export
        :query {} export: Export definition
        :query str error: Detail of the exception raised

    """

    label = ""
    if export:
        label = export['label']

    msg = """
        Bonjour,
        <p>
            Votre export <i>{}</i> n'a pas fonctionné correctement.
        </p>
        <p>
            <b>Detail : </b>
            {}
        </p>
        <p>
            Veuillez signaler le problème à l'administrateur du site.
        </p>
    """.format(label, error)

    # Si configuration de mail_on_error
    #   envoie d'un mail d'erreur à l'administrateur
    if "ERROR_MAIL_TO" in current_app.config:
        if (
            type(current_app.config["ERROR_MAIL_TO"]) is list
            and
            current_app.config["ERROR_MAIL_TO"]
        ):
            export_send_admin_mail_error(
                current_app.config["ERROR_MAIL_TO"],
                export,
                error
            )

    send_mail(
        recipients=mail_to,
        subject="[GeoNature][ERREUR] Export {}".format(label),
        msg_html=msg
    )
def test_mail_config(gn_app):
    """
        Fonction qui test si l'envoie de mail est
        possible et correctement configuré lors de l'installation du module
    """
    if gn_app.config['MAIL_CONFIG']:
        print(" ...Test mail configuration")
        send_mail(
            [gn_app.config['MAIL_CONFIG']['MAIL_USERNAME']],
            "[GeoNature][Export]Installation module export",
            "Si vous avez reçu ce mail c'est que les paramètres de configuration des mails sont corrects et que le module est en cours d'installation"  # noqa: E501
        )
    else:
        raise GNModuleInstallError("Mail config is mandatory")
Exemple #9
0
def validate_temp_user(data):
    """
       Send an email after the action of account creation.

       :param admin_validation_required: if True an admin will receive an
       email to validate the account creation else the user himself
       receive the email.
       :type admin_validation_required: bool
    """
    token = data.get("token", None)

    user = DB.session.query(TempUser).filter(
        TempUser.token_role == token).first()

    if not user:
        return {
            "msg":
            "{token}: ce token n'est pas associé à un compte temporaire".
            format(token=token)
        }
    user_dict = user.as_dict()
    subject = "Demande de création de compte GeoNature"
    if current_app.config["ACCOUNT_MANAGEMENT"]["AUTO_ACCOUNT_CREATION"]:
        template = "email_self_validate_account.html"
        recipients = [user.email]
    else:
        template = "email_admin_validate_account.html"
        recipients = [
            current_app.config["ACCOUNT_MANAGEMENT"]["VALIDATOR_EMAIL"]
        ]
    url_validation = url_for("users.confirmation",
                             token=user.token_role,
                             _external=True)

    msg_html = render_template(
        template,
        url_validation=url_validation,
        user=user_dict,
        additional_fields=[{
            "key": key,
            "value": value
        } for key, value in (user_dict.get("champs_addi") or {}).items()],
    )

    send_mail(recipients, subject, msg_html)

    return {"msg": "ok"}
def send_email_for_recovery(data):
    """
    Send an email with the login of the role and the possibility to reset
    its password
    """
    user = data["role"]
    recipients = current_app.config["MAIL_CONFIG"]["MAIL_USERNAME"]
    url_password = current_app.config["URL_APPLICATION"] + "#/new-password?token=" + data["token"]

    msg_html = render_template(
        "email_login_and_new_pass.html",
        identifiant=user["identifiant"],
        url_password=url_password,
    )
    subject = "Confirmation changement Identifiant / mot de passe"
    send_mail([user["email"]], subject, msg_html)
    return {"msg": "ok"}
Exemple #11
0
def inform_user(user):
    """
    Send an email to inform the user that his account was validate.
    """
    app_name = current_app.config["appName"]
    app_url = current_app.config["URL_APPLICATION"]

    msg_html = render_template(
        "email_confirm_user_validation.html",
        user_firstname=user["prenom_role"],
        user_lastname=user["nom_role"],
        app_name=app_name,
        app_url=app_url,
        user_login=user["identifiant"],
    )
    subject = f"Confirmation inscription {app_name}"
    send_mail([user["email"]], subject, msg_html)
def inform_user(user):
    """
    Send an email to inform the user that his account was validate.
    """
    app_name = current_app.config["appName"]
    app_url = current_app.config["URL_APPLICATION"]
    text_addon = current_app.config["ACCOUNT_MANAGEMENT"]["ADDON_USER_EMAIL"]
    html_text_addon = Markup(text_addon)

    msg_html = render_template(
        "email_confirm_user_validation.html",
        user_firstname=user["prenom_role"],
        user_lastname=user["nom_role"],
        app_name=app_name,
        app_url=app_url,
        user_login=user["identifiant"],
        text_addon=html_text_addon,
    )
    subject = f"Confirmation inscription {app_name}"
    send_mail([user["email"]], subject, msg_html)
Exemple #13
0
def publish_acquisition_framework_mail(af, info_role):
    """
    Method for sending a mail during the publication process
    """

    # Parsing the AF XML from MTD to get the idTPS parameter
    af_xml = mtd_utils.get_acquisition_framework(
        str(af.unique_acquisition_framework_id).upper())
    xml_parser = ET.XMLParser(ns_clean=True, recover=True, encoding="utf-8")
    namespace = current_app.config["XML_NAMESPACE"]
    root = ET.fromstring(af_xml, parser=xml_parser)
    try:
        ca = root.find(".//" + namespace + "CadreAcquisition")
        ca_idtps = mtd_utils.get_tag_content(ca, "idTPS")
    except AttributeError:
        ca_idtps = ""

    # Generate the links for the AF's deposite certificate and framework download
    pdf_url = current_app.config[
        "API_ENDPOINT"] + "/meta/acquisition_frameworks/export_pdf/" + str(
            af.id_acquisition_framework)

    # Mail subject
    mail_subject = "Dépôt du cadre d'acquisition " + str(
        af.unique_acquisition_framework_id).upper()
    mail_subject_base = current_app.config["METADATA"][
        "MAIL_SUBJECT_AF_CLOSED_BASE"]
    if mail_subject_base:
        mail_subject = mail_subject_base + " " + mail_subject
    if ca_idtps:
        mail_subject = mail_subject + " pour le dossier {}".format(ca_idtps)

    # Mail content
    mail_content = f"""Bonjour,<br>
    <br>
    Le cadre d'acquisition <i> "{af.acquisition_framework_name}" </i> dont l’identifiant est
    "{str(af.unique_acquisition_framework_id).upper()}" que vous nous avez transmis a été déposé"""

    mail_content_additions = current_app.config["METADATA"][
        "MAIL_CONTENT_AF_CLOSED_ADDITION"]
    mail_content_pdf = current_app.config['METADATA'][
        "MAIL_CONTENT_AF_CLOSED_PDF"]
    mail_content_greetings = current_app.config['METADATA'][
        "MAIL_CONTENT_AF_CLOSED_GREETINGS"]

    if ca_idtps:
        mail_content = mail_content + f"dans le cadre du dossier {ca_idtps}"

    if mail_content_additions:
        mail_content = mail_content + mail_content_additions
    else:
        mail_content = mail_content + ".<br>"

    if mail_content_pdf:
        mail_content = mail_content + mail_content_pdf.format(
            pdf_url) + pdf_url + "<br>"

    if mail_content_greetings:
        mail_content = mail_content + mail_content_greetings

    # Mail recipients : if the publisher is the the AF digitizer, we send a mail to both of them
    mail_recipients = set()
    cur_user = DB.session.query(User).get(info_role.id_role)
    if cur_user and cur_user.email:
        mail_recipients.add(cur_user.email)

    if af.id_digitizer:
        digitizer = DB.session.query(User).get(af.id_digitizer)
        if digitizer and digitizer.email:
            mail_recipients.add(digitizer.email)
    # Mail sent
    if mail_subject and mail_content and len(mail_recipients) > 0:
        mail.send_mail(list(mail_recipients), mail_subject, mail_content)