示例#1
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool send = false;

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
            string rtfString       = File.ReadAllText(path_SendRtfFile);

            r.ImageStyle.IncludeImageInHtml = true;
            string text = r.ConvertString(rtfString);
            int    n    = 1;

            foreach (var vari in whomMailList.Items)
            {
                int progressPercentage = Convert.ToInt32(((double)n++ / whomMailList.Items.Count) * 100);
                (sender as BackgroundWorker).ReportProgress(progressPercentage);
                send_mes("Новое письмо", text, filePathList, (string)vari);
                send = true;
            }

            e.Result = send;
        }
示例#2
0
        public void EnvoiMessageAvecPJ(string destinataire, string cc, string message, string objet, string pj, string adresseAMettre)
        {
            try
            {
                //Objet Mail
                msg = new MailMessage();

                // Expéditeur
                msg.From = new MailAddress(this.adresseExpediteur, this.nomExpediteur);

                // Destinataire(s)
                foreach (String dest in destinataire.Split(';'))
                {
                    msg.To.Add(new MailAddress(dest, dest));
                }

                // Destinataire(s) en copie
                if (cc != null && cc != "")
                {
                    foreach (String destcc in cc.Split(';'))
                    {
                        msg.CC.Add(new MailAddress(destcc));
                    }
                }

                //Objet du mail
                msg.Subject = objet;

                //Corps du mail
                //Contenu du mail
                SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
                r.ImageStyle.IncludeImageInHtml = true;
                System.Collections.ArrayList arListWithImages = new System.Collections.ArrayList();
                string html = r.ConvertString(message, arListWithImages).Replace("Trial version can convert up to 30000 symbols.", "").Replace("Get the full featured version!", "");

                //Signature
                string signature = "";
                if (((App)App.Current)._connectedUser.Signature != null)
                {
                    signature = ((App)App.Current)._connectedUser.Signature;
                }

                //Logo
                string image = "<br /><br /><img src=cid:companylogo>";
                string cheminimage = "logo.gif";

                //Adresse
                string adresse = "<br />Tél : +33 (0)2 43 49 17 55 – Fax : +33 (0)2 43 49 02 29<br />P.A des Morandières - Bd de Galilée<br />53810 CHANGE - LAVAL";
                if (((App)App.Current)._connectedUser.Salarie_Interne1 != null)
                {
                    if (((App)App.Current)._connectedUser.Salarie_Interne1.Entreprise_Mere1 != null)
                    {
                        if (((App)App.Current)._connectedUser.Salarie_Interne1.Entreprise_Mere1.AdresseEMail != null)
                        {
                            adresse = ((App)App.Current)._connectedUser.Salarie_Interne1.Entreprise_Mere1.AdresseEMail;
                            cheminimage = ((App)App.Current)._connectedUser.Salarie_Interne1.Entreprise_Mere1.Logo;
                        }
                    }
                }

                //Mentions légales
                string MentLeg = "<br />Ce message (y compris les pièces jointes) est rédigé a l'intention exclusive de ses destinataires et peut contenir des informations confidentielles. Si vous recevez ce message par erreur, merci de le détruire et d'en avertir immédiatement l'expéditeur. Si vous n'êtes pas un destinataire, toute utilisation est non-autorisée et peut être illégale. Tout message électronique est susceptible d'altération et son intégrité ne peut être assurée. La société SIT (et ses filiales) décline(nt) toute responsabilité au titre de ce message, dans l'hypothèse ou il aurait été modifié. Merci.<br />This message (including any attachments) is intended solely for the use of the addressee(s) and may contain confidential informations.<br />If you receive this message in error, please delete it and immediately notify the sender.If the reader of this message is not the intended recipient, you are hereby notified that any unauthorized use, copying or dissemination is prohibited. E-mails are susceptible to alteration and their integrity cannot be guaranteed. Neither SIT group nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or falsified. Thank you.<br />";

                String contenuMail = html + signature + image + adresse + MentLeg;

                System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(contenuMail, null, "text/html");
                //Lien de l'image CID dans la vue
                LinkedResource logo = new LinkedResource("\\\\stockagenas\\sitaff\\images\\" + cheminimage);
                logo.ContentId = "companylogo";
                htmlView.LinkedResources.Add(logo);

                //Ajout de la vue dans le mail
                msg.AlternateViews.Add(htmlView);

                //ajout de la pj
                Attachment piecejointe = new Attachment(pj);
                msg.Attachments.Add(piecejointe);

                //Ajout de l'adresse mail de la personne qui envoi si elle existe
                if (((App)App.Current)._connectedUser.Salarie_Interne1 != null)
                {
                    if (((App)App.Current)._connectedUser.Salarie_Interne1.Salarie != null)
                    {
                        if (((App)App.Current)._connectedUser.Salarie_Interne1.Salarie.Personne != null)
                        {
                            if (((App)App.Current)._connectedUser.Salarie_Interne1.Salarie.Personne.EMail_Pro != null && ((App)App.Current)._connectedUser.Salarie_Interne1.Salarie.Personne.EMail_Pro != "")
                            {
                                try
                                {
                                    msg.From = new MailAddress(((App)App.Current)._connectedUser.Salarie_Interne1.Salarie.Personne.EMail_Pro);
                                    msg.CC.Add(new MailAddress(((App)App.Current)._connectedUser.Salarie_Interne1.Salarie.Personne.EMail_Pro));
                                }
                                catch (Exception) { }
                            }
                            else
                            {
                                if (((App)App.Current)._connectedUser.Salarie_Interne1.Salarie.Personne.EMail != null && ((App)App.Current)._connectedUser.Salarie_Interne1.Salarie.Personne.EMail != "")
                                {
                                    try
                                    {
                                        msg.From = new MailAddress(((App)App.Current)._connectedUser.Salarie_Interne1.Salarie.Personne.EMail);
                                        msg.CC.Add(new MailAddress(((App)App.Current)._connectedUser.Salarie_Interne1.Salarie.Personne.EMail));
                                    }
                                    catch (Exception) { }
                                }
                            }
                        }
                    }
                }

                // Configuration SMTP
                client = new SmtpClient(SMTP, portSMTP);
                client.EnableSsl = false;
                client.Credentials = new NetworkCredential(SMTPUser, MDPSMTPUser);

                // Envoi du mail
                client.Send(msg);

                //Tue le mail
                msg.Dispose();
                //Ferme la connexion au SMTP
                client.Dispose();
            }
            catch (Exception ex)
            {
                //Tue le mail
                if (msg != null)
                {
                    msg.Dispose();
                }
                //Ferme la connexion au SMTP
                if (client != null)
                {
                    client.Dispose();
                }
                throw new Exception(ex.Message);
            }
        }
示例#3
0
        private void exportToHMTLDatabseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string rtf = "", html = "";
            int id = 0, category_id = 0;
            string name = "", note_text = "";
            // get test text from database
            for (int i = 1; i < 109; i++)
            {
                StringBuilder query = new StringBuilder();
                query.Append("SELECT id, category_id, name, note_text ");
                query.Append("FROM notes ");
                query.Append("WHERE id=" + i);

                using (SQLiteCommand cmd = new SQLiteCommand(query.ToString(), dbConnection))
                {
                    using (SQLiteDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr.IsDBNull(0))
                                continue;
                            else
                            {
                                id = dr.IsDBNull(0) ? 0 : dr.GetInt32(0);
                                category_id = dr.IsDBNull(1) ? 0 : dr.GetInt32(1);
                                name = dr.IsDBNull(2) ? "" : dr.GetString(2);
                                note_text = dr.IsDBNull(3) ? "" : dr.GetString(3);
                            }
                        }
                    }
                }

                rtf = note_text;
                SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
                r.Encoding = SautinSoft.eEncoding.UTF_8;
                r.OutputFormat = SautinSoft.eOutputFormat.HTML_32;
                html = r.ConvertString(rtf);
                note_text = html;

                StringBuilder insert = new StringBuilder();
                insert.Append("INSERT into Notes_Backup (id, category_id, name, note_text) ");
                insert.Append("VALUES (" + id + ", " + category_id + ", '" + name.Replace("'", "''") + "', '" + note_text.Replace("'", "''") + "')");

                using (SQLiteCommand cmd = new SQLiteCommand(insert.ToString(), dbConnection))
                {
                    using (SQLiteDataReader dr = cmd.ExecuteReader())
                    {
                        //MessageBox.Show(dr.ToString());
                    }
                }
            }
        }