Esempio n. 1
0
    // Envoyer l'email a l'interviewe (Personne)
    public static string EnvoyerEmailQuestionnaire(MailAddress mailTo, string civilite, string nom, string prenom, string societe, string code, string sujet, string guid)
    {
        string     status     = "";
        SmtpServer smtpServer = SmtpServer.Get(SessionState.MemberInfo.MembreGUID);

        if (smtpServer == null)
        {
            // COR04112009
            string msg = "Pas de serveur SMTP configuré pour cet utilisateur : " + SessionState.MemberInfo.NomUtilisateur + "<br/>";
            msg += "Pour envoyer des emails à vos interviewés, vous devez configurer un compte d'emails :<br/><br/>";
            msg += "<span class=\"SpanHyperLinkStyle\">";
            msg += "<a href=\"Admin/Page/SettingsSmtp.aspx\" class=\"HyperLinkStyle\" >Configurez votre serveur d'emails</a>";
            msg += "</span>";
            //HttpContext.Current.Response.Redirect( Tools.PageErreurPath + msg );
            Tools.PageValidation(msg);
        }

        string utilisateur = WebContent.GetUtilisateur();

        //
        // Il y a t-il une Page Email pour ce Questionnaire
        //
        WebContent webContent = null;

        webContent = WebContent.GetWebContent("CorpsEmail", utilisateur, code);

        // Sinon il y a-til un email pour Tout Le Monde
        if (webContent == null)
        {
            webContent = WebContent.GetWebContent("CorpsEmail", utilisateur, WebContent.ToutLeMonde);
        }

        // Et Sinon c'est une erreur
        if (webContent == null)
        {
            string msg = "Pas de section CorpsEmail configuré pour cet utilisateur : " + utilisateur;
            msg += "<br/>Demandez à l'administrateur";
            Tools.PageValidation(msg);
        }

        //
        // Deux moyens de contacter l'interviewer
        // Soit par le %%LIEN%%
        // Soit par %%ADRESSE_EMAIL%% ET %%CODE_ACCES%% ET %%LOG%%
        //
        LogonInterviewe logon = new LogonInterviewe(webContent.SectionContent);

        if (logon.Message != "")
        {
            Tools.PageValidation(logon.Message);
        }

        MailMessage mail = new MailMessage();

        mail.From = new MailAddress(smtpServer.Email, smtpServer.UserName);
        mail.To.Add(mailTo);
        mail.Subject = smtpServer.EmailSubject + " " + sujet;

        string body = webContent.SectionContent;

        body = body.Replace("%%CIVILITE%%", civilite);
        body = body.Replace("%%NOM%%", nom);
        body = body.Replace("%%PRENOM%%", prenom);
        body = body.Replace("%%SOCIETE%%", societe);
        if (logon.Automatique)
        {
            string lien = Utils.WebSiteUri.ToLower() + "/contact/login.aspx?guid=" + guid;
            body = body.Replace("%%LIEN%%", lien);
        }
        if (logon.AdresseEmailEtCode)
        {
            string log = Utils.WebSiteUri.ToLower() + "/contact/login.aspx";
            body = body.Replace("%%ADRESSE_EMAIL%%", mailTo.Address);
            body = body.Replace("%%CODE_ACCES%%", code);
            body = body.Replace("%%LOG%%", log);
        }
        mail.Body       = body;
        mail.IsBodyHtml = true; // A voir ...

        SmtpClient smtp = new SmtpClient(smtpServer.ServerName);

        smtp.Credentials = new System.Net.NetworkCredential(smtpServer.UserName, smtpServer.UserPassWord);
        smtp.EnableSsl   = smtpServer.EnableSSL;
        smtp.Port        = smtpServer.ServerPort;

        try
        {
            smtp.Send(mail);
            status = mailTo.Address + " message envoyé";
            //OnEmailSent( mail ); on veut renvoyer status, on ne peut pas deleguer
        }
        catch (SmtpException ex)
        {
            status  = "Connexion impossible.<br>";
            status += ex.Message;
            //OnEmailFailed( mail ); on veut renvoyer status, on ne peut pas deleguer
        }
        finally
        {
            // Remove the pointer to the message object so the GC can close the thread.
            mail.Dispose();
            mail = null;
        }
        return(status);
    }
Esempio n. 2
0
    protected void ButtonSauver_Click(object sender, System.EventArgs e)
    {
        if (DropDownListWebContentSection.SelectedSection == "-1")
        {
            SessionState.ValidationMessage += "Sélectionnez une Section.<br/>";
        }
        if (!WebContent.CanEdit())
        {
            SessionState.ValidationMessage += "Vous n'avez pas les droits pour éditer cette section.<br/>";
        }
        if (SessionState.ValidationMessage != null)
        {
            Response.Redirect(Request.RawUrl);
        }

        string newContenu = "";
        string oldContenu = "";

        if (FCKeditor1.Value == "")
        {
            newContenu = "<p></p>";
        }
        else
        {
            newContenu = FCKeditor1.Value;
        }

        oldContenu = SessionState.WebContent.SectionContent;
        SessionState.WebContent.SectionContent = newContenu;
        SessionState.WebContent.Section        = DropDownListWebContentSection.SelectedSection;

        if (DropDownListWebContentSection.SelectedSection == "CorpsEmail")
        {
            LogonInterviewe logon = new LogonInterviewe(newContenu);
            if (logon.Message != "")
            {
                ValidationMessage.Text    = logon.Message;
                ValidationMessage.Visible = true;
                return;
            }
        }

        if (User.IsInRole("Administrateur"))
        {
            if (DropDownListMembre.SelectedMembre != "-1")
            {
                // Admin sauve la page pour lui meme
                if (DropDownListMembre.SelectedMembre == "-1")
                {
                    SessionState.WebContent.Utilisateur = WebContent.Admin;
                }
                else // Trouver l'utilisateur
                {
                    Guid       membreGuid = ( Guid )DropDownListMembre.MembreGUID[DropDownListMembre.SelectedIndex - 1];
                    MemberInfo membre     = MemberInfo.Get(membreGuid);
                    SessionState.WebContent.Utilisateur = membre.NomUtilisateur;
                }
            }
        }

        string codeAccess = "";

        if (DropDownListQuestionnaire.SelectedQuestionnaire == "-1")   // "-1" valeur mise par le composant
        {
            codeAccess = WebContent.ToutLeMonde;
        }
        else
        {
            codeAccess = DropDownListQuestionnaire.SelectedCodeAcces;
        }
        SessionState.WebContent.Visualisateur = codeAccess;

        int status = WebContent.Update(SessionState.WebContent);

        if (status == 2)   // n'existe pas
        {
            // l'utilisateur a changer le visualisateur d'une page existante
            SessionState.ValidationMessage += "La Page n'existait pas.<br/>";
            int statusCreate = WebContent.Create(SessionState.WebContent);
            if (statusCreate != 1)
            {
                SessionState.ValidationMessage += "Erreur à la Creation de cette Page.<br/>";
            }
            else
            {
                SessionState.ValidationMessage += "Elle est créée avec succès.<br />";
            }

            // Create a le bon gout de mettre a jour l'id du nouvel objet cree
            Response.Redirect("~/WebContent/Edit.aspx?id=" + SessionState.WebContent.WebContentID);
        }
        if (status == 0)
        {
            SessionState.ValidationMessage += "Erreur serveur à la mise à jour de la Page.<br/>";
            Response.Redirect(Request.RawUrl);
        }

        // Update
        string adrIP = Request.ServerVariables["REMOTE_ADDR"];

        if (Global.SettingsXml.EnvoyerMiseAjour == true)
        {
            Courriel.EnvoyerMiseAJour(oldContenu, newContenu, "Mise à jour", SessionState.WebContent.Section, adrIP);
        }

        if (Request["ReturnURL"] != null)
        {
            Response.Redirect(Request["ReturnURL"].ToString());
        }
        else
        {
            Response.Redirect("~/WebContent/Manage.aspx");
        }
    }