Example #1
0
 static void Main(string[] args)
 {
     var logger = new FileWriter();
     var paramsReader = new ParamsReader(args, logger);
     var fileChecker = new FileChecker(paramsReader);
     var mailComposer = new MailMessageComposer(paramsReader);
     var mailSender = new MailClientSender(fileChecker, paramsReader, logger);
     mailSender.SetData(mailComposer);
     //Console.ReadLine();
 }
Example #2
0
        /// <summary>
        /// Metodo per la creazione di un nuovo messaggio
        /// (Per la send)
        /// </summary>
        private Message CreateNewMessage()
        {
            //se esiste il messaggio corrente, riprendo lo stesso
            if (MailMessageComposer.CurrentSendMailExist())
            {
                return(MailMessageComposer.CurrentSendMailGet());
            }
            //altrimenti costruisco un nuovo messaggio
            MailMessageComposer mmc = new MailMessageComposer();

            mmc.CurrentSendMail_NEW();
            return(mmc.message);
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //per le immagini embedded
            if (Request.QueryString["cont"] != null)
            {
                string content = Request.QueryString["cont"];
                Response.Clear();
                Message msg = MailMessageComposer.CurrentSendMailGet();
                if (msg == null)
                {
                    return;
                }
                foreach (MimePart m in msg.EmbeddedObjects)
                {
                    if (m.ContentId.Equals("<" + content + ">"))
                    {
                        Response.ContentType = m.ContentType.ToString();
                        Response.OutputStream.Write(m.BinaryContent, 0, m.BinaryContent.Length);
                        Response.Flush();
                        Response.End();
                        return;
                    }
                }

                foreach (MimePart m in msg.UnknownDispositionMimeParts)
                {
                    if (m.ContentId.Equals("<" + content + ">"))
                    {
                        Response.ContentType = m.ContentType.ToString();
                        Response.OutputStream.Write(m.BinaryContent, 0, m.BinaryContent.Length);
                        Response.Flush();
                        Response.End();
                        return;
                    }
                }

                Response.Flush();
                Response.End();
                return;
            }

            ToTextBox.ReadOnly      = false;
            CCTextBox.ReadOnly      = false;
            BCCTextBox.ReadOnly     = false;
            SubjectTextBox.ReadOnly = false;
            BodyTextBox.ReadOnly    = false;
        }
Example #4
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                Message msg;
                ComunicazioniService comunicazioniService = new ComunicazioniService();
                if (MailMessageComposer.CurrentSendMailExist())
                {
                    msg = MailMessageComposer.CurrentSendMailGet();
                }
                else
                {
                    msg = new Message();
                }

                msg.Subject = SubjectTextBox.Text;
                if (String.IsNullOrEmpty(ToTextBox.Text.Trim()) &&
                    String.IsNullOrEmpty(CCTextBox.Text.Trim()) &&
                    String.IsNullOrEmpty(BCCTextBox.Text.Trim()))
                {
                    ErrorLabel.Text    = "Inserire almeno un destinatario";
                    ErrorLabel.Visible = true;
                    return;
                }
                msg.To.Clear();
                msg.Cc.Clear();
                msg.Bcc.Clear();
                this.addEmailsTo(ToTextBox.Text, msg);
                this.addEmailsCc(CCTextBox.Text, msg);
                this.addEmailCcn(BCCTextBox.Text, msg);
                msg.Date = System.DateTime.Now;
                //mantengo il vecchio testo perché in caso di ErrorEventArgs lo devo ripristinare
                bodyBag = msg.BodyHtml.Text;
                SendMail.Model.BodyChunk bb = new SendMail.Model.BodyChunk();
                string   txt = BodyTextBox.Text;
                string[] lst = txt.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                foreach (string l in lst)
                {
                    bb.Line.Add(l);
                }
                //inserisco il testo libero in testa a quello preformattato
                HtmlNode newNode = null;
                if (bb.Line.Count != 0)
                {
                    newNode = HtmlNode.CreateNode(bb.getAsHtml());
                }
                HtmlDocument d = new HtmlDocument();
                if (!String.IsNullOrEmpty(PreformattedBody.Text))
                {
                    d.LoadHtml(PreformattedBody.Text);
                }
                if (newNode != null)
                {
                    if (d.DocumentNode.Descendants().Count() != 0)
                    {
                        HtmlNode root = d.DocumentNode.Descendants().SingleOrDefault(x => x.Name.Equals("body", StringComparison.InvariantCultureIgnoreCase));
                        if (root == null)
                        {
                            root = d.DocumentNode.Descendants().FirstOrDefault(x => x.NodeType == HtmlNodeType.Element);
                        }
                        if (root != null)
                        {
                            root.PrependChild(newNode);
                        }
                        else
                        {
                            d.DocumentNode.PrependChild(newNode);
                        }
                    }
                    else
                    {
                        d.DocumentNode.PrependChild(newNode);
                    }
                }
                msg.BodyHtml.Text = d.DocumentNode.InnerHtml;
                //se non sono inclusi gli allegati originali
                if (MailEditabile == true && cbIncludiAllegati.Checked == false)
                {
                    for (int i = 0; i < msg.Attachments.Count; i++)
                    {
                        //rimuovo gli allegati originali
                        if (msg.Attachments[i].ParentMessage != null)
                        {
                            msg.Attachments.RemoveAt(i);
                        }
                    }
                }
                foreach (MimePart mm in msg.Attachments)
                {
                    if (mm.BinaryContent == null || mm.BinaryContent.Length < 10)
                    {
                        if (!String.IsNullOrEmpty(mm.ContentId))
                        {
                            string idAttach = mm.ContentId.Trim(new char[] { '<', '>' });
                            long   idAtt    = -1;
                            if (long.TryParse(idAttach, out idAtt))
                            {
                                ComAllegato all = comunicazioniService
                                                  .LoadAllegatoComunicazioneById(long.Parse(idAttach));
                                mm.BinaryContent = all.AllegatoFile;
                            }
                        }
                    }
                }
                switch (CurrentAction)
                {
                case MailActions.REPLY_TO:
                case MailActions.REPLY_ALL:
                case MailActions.RE_SEND:
                case MailActions.FORWARD:
                    msg.InReplyTo = msg.Id.ToString();
                    break;
                }

                ActiveUp.Net.Mail.DeltaExt.MailUser mailUser = null;
                if (WebMailClientManager.AccountExist())
                {
                    mailUser = WebMailClientManager.getAccount();
                }

                if (mailUser != null)
                {
                    MailServerFacade f = MailServerFacade.GetInstance(mailUser);

                    if (mailUser.IsManaged)
                    {
                        try
                        {
                            SendMail.Model.ComunicazioniMapping.Comunicazioni c =
                                new SendMail.Model.ComunicazioniMapping.Comunicazioni(
                                    SendMail.Model.TipoCanale.MAIL,
                                    this.SottoTitolo,
                                    msg,
                                    MySecurityProvider.CurrentPrincipal.MyIdentity.UserName, 2, "O");
                            if (c.MailComunicazione.MailRefs != null && c.MailComunicazione.MailRefs.Count != 0)
                            {
                                c.RubricaEntitaUsed = (from cont in c.MailComunicazione.MailRefs
                                                       select new SendMail.Model.ComunicazioniMapping.RubrEntitaUsed
                                {
                                    Mail = cont.MailDestinatario,
                                    TipoContatto = cont.TipoRef
                                }).ToList();
                            }

                            comunicazioniService.InsertComunicazione(c);
                        }
                        catch (Exception ex)
                        {
                            ManagedException mex = new ManagedException("Errore nel salvataggio della mail",
                                                                        "MAIL_CMP_002", "", ex.StackTrace, ex);
                            ErrorLog err = new ErrorLog(mex);
                            _log.Error(err);
                            ErrorLabel.Text    = "Errore nell'invio del messaggio";
                            ErrorLabel.Visible = true;
                            return;
                        }
                    }
                    else
                    {
                        f.sendMail(msg);
                    }

                    (this.Page as BasePage).info.AddInfo("Il messaggio e' stato spedito correttamente");
                    MailMessageComposer.CurrentSendMailClear();
                    onMailSent();
                }
                else
                {
                    ((BasePage)this.Page).info.AddInfo("Account inesistente.");
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(ManagedException))
                {
                    _log.Error(new Com.Delta.Logging.Errors.ErrorLog(new ManagedException(ex.Message, "FAC_007", string.Empty, string.Empty, ex)));
                }
                //_log.Error(new Com.Delta.Logging.Errors.ErrorLog("FAC_007", ex, string.Empty, string.Empty, string.Empty));

                MailMessageComposer.CurrentSendMailGet().BodyHtml.Text = bodyBag;
                ErrorLabel.Visible = true;
                ErrorLabel.Text    = ex.Message;
                return;
            }
            Label5.Visible = true;
        }
Example #5
0
 /// <summary>
 /// Metodo per il caricamento del messaggio corrente
 /// </summary>
 /// <returns></returns>
 private Message GetCurrentMessage()
 {
     if (MailMessageComposer.CurrentSendMailExist())
     {
         return(MailMessageComposer.CurrentSendMailGet());
     }
     else
     {
         Message msg = GetOriginalMessage();
         if (msg == null)
         {
             return(null);
         }
         else
         {
             try
             {
                 int idOri = msg.Id;
                 if (msg.OriginalData == null)
                 {
                     msg = Parser.ParseMessage(msg.ToMimeString());
                 }
                 else
                 {
                     msg = Parser.ParseMessage(msg.OriginalData);
                 }
                 msg.Id = idOri;
             }
             catch (OutOfMemoryException oomEx)
             {
                 ManagedException mEx = new ManagedException(
                     "Memoria insufficiente. Chiudere il popup e riprovare.",
                     "MAIL_CMP_001",
                     string.Empty,
                     string.Empty,
                     oomEx);
                 ErrorLog err = new ErrorLog(mEx);
                 _log.Error(err);
                 (this.Page as BasePage).info.AddMessage(mEx, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                 throw;
             }
             catch (Exception ex)
             {
                 if (ex.GetType() != typeof(ManagedException))
                 {
                     ManagedException mEx = new ManagedException(
                         "Errore nel recupero del messaggio originale",
                         "MAIL_CMP_002",
                         string.Empty,
                         string.Empty,
                         ex);
                     ErrorLog err = new ErrorLog(mEx);
                     _log.Error(err);
                     (this.Page as BasePage).info.AddMessage(mEx, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                 }
                 throw;
             }
         }
         MailMessageComposer mc = new MailMessageComposer();
         mc.message = msg;
         return(msg);
     }
 }
Example #6
0
        public void Initialize(MailActions action, String sottoTitolo)
        {
            ErrorLabel.Visible = false;
            Label5.Visible     = false;
            this.SottoTitolo   = sottoTitolo;
            CurrentAction      = action;
            BodyTextBox.Text   = string.Empty;
            if (MailMessageComposer.CurrentSendMailExist())
            {
                BodyTextBox.Text = MailMessageComposer.CurrentSendMailGet().BodyText.Text;
            }
            this.Visible = true;
            switch (action)
            {
            case MailActions.REPLY_ALL:
                DivsVisibility[Divs.Attachments]    = false;
                DivsVisibility[Divs.NewAttachments] = true;
                if (LoadMessageReplyAll() == false)
                {
                    return;
                }
                break;

            case MailActions.REPLY_TO:
                DivsVisibility[Divs.Attachments]    = false;
                DivsVisibility[Divs.NewAttachments] = true;
                if (LoadMessageReply() == false)
                {
                    return;
                }
                break;

            case MailActions.SEND:
                DivsVisibility[Divs.Attachments]    = true;
                DivsVisibility[Divs.NewAttachments] = true;
                if (LoadMessageSend() == false)
                {
                    return;
                }
                break;

            case MailActions.FORWARD:
                DivsVisibility[Divs.Attachments]    = true;
                DivsVisibility[Divs.NewAttachments] = true;
                if (LoadMessageForward() == false)
                {
                    return;
                }
                break;

            case MailActions.RE_SEND:
                DivsVisibility[Divs.Attachments]    = true;
                DivsVisibility[Divs.NewAttachments] = false;
                if (LoadMessageReSend() == false)
                {
                    return;
                }
                break;

            default:
                break;
            }
            pnlMail.DataBind();
        }
Example #7
0
        public HttpResponseMessage SendMailExt(FormDataCollection collection)
        {
            MailModel model = new MailModel();
            string    bodyBag;

            try
            {
                Message msg;
                ComunicazioniService comunicazioniService = new ComunicazioniService();
                if (MailMessageComposer.CurrentSendMailExist())
                {
                    msg = MailMessageComposer.CurrentSendMailGet();
                }
                else
                {
                    msg = new Message();
                }

                msg.Subject = collection["Oggetto"];
                if (String.IsNullOrEmpty(collection["DestinatarioA"]) &&
                    String.IsNullOrEmpty(collection["DestinatarioCC"]) &&
                    String.IsNullOrEmpty(collection["DestinatarioBCC"]))
                {
                    model.message = "Inserire almeno un destinatario";
                    model.success = "false";
                    return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model));
                }
                msg.To.Clear();
                msg.Cc.Clear();
                msg.Bcc.Clear();
                this.addEmailsTo(collection["DestinatarioA"].Trim(), msg);
                if (!(string.IsNullOrEmpty(collection["DestinatarioCC"])))
                {
                    this.addEmailsCc(collection["DestinatarioCC"], msg);
                }
                if (!(string.IsNullOrEmpty(collection["DestinatarioBCC"])))
                {
                    this.addEmailCcn(collection["DestinatarioBCC"], msg);
                }
                msg.Date = System.DateTime.Now;
                //mantengo il vecchio testo perché in caso di ErrorEventArgs lo devo ripristinare
                bodyBag = msg.BodyHtml.Text;
                SendMail.Model.BodyChunk bb = new SendMail.Model.BodyChunk();
                string   txt = collection["TestoMail"];
                string[] lst = txt.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                foreach (string l in lst)
                {
                    bb.Line.Add(l);
                }
                //inserisco il testo libero in testa a quello preformattato
                HtmlNode newNode = null;
                if (bb.Line.Count != 0)
                {
                    newNode = HtmlNode.CreateNode(bb.getAsHtml());
                }
                HtmlDocument d = new HtmlDocument();
                if (newNode != null)
                {
                    if (d.DocumentNode.Descendants().Count() != 0)
                    {
                        HtmlNode root = d.DocumentNode.Descendants().SingleOrDefault(x => x.Name.Equals("body", StringComparison.InvariantCultureIgnoreCase));
                        if (root == null)
                        {
                            root = d.DocumentNode.Descendants().FirstOrDefault(x => x.NodeType == HtmlNodeType.Element);
                        }
                        if (root != null)
                        {
                            root.PrependChild(newNode);
                        }
                        else
                        {
                            d.DocumentNode.PrependChild(newNode);
                        }
                    }
                    else
                    {
                        d.DocumentNode.PrependChild(newNode);
                    }
                }
                msg.BodyHtml.Text = d.DocumentNode.InnerHtml;
                //se non sono inclusi gli allegati originali
                if (!(string.IsNullOrEmpty(collection["IncludiAllegati"])) && collection["IncludiAllegati"].ToUpper() == "FALSE")
                {
                    for (int i = 0; i < msg.Attachments.Count; i++)
                    {
                        //rimuovo gli allegati originali
                        if (msg.Attachments[i].ParentMessage != null)
                        {
                            msg.Attachments.RemoveAt(i);
                        }
                    }
                }
                msg.InReplyTo = msg.Id.ToString();
                ActiveUp.Net.Mail.DeltaExt.MailUser mailUser = null;
                if (WebMailClientManager.AccountExist())
                {
                    mailUser = WebMailClientManager.getAccount();
                }

                if (mailUser != null)
                {
                    MailServerFacade f = MailServerFacade.GetInstance(mailUser);
                    msg.From = new Address(mailUser.Casella);
                    if (mailUser.IsManaged)
                    {
                        try
                        {
                            SendMail.Model.ComunicazioniMapping.Comunicazioni c =
                                new SendMail.Model.ComunicazioniMapping.Comunicazioni(
                                    SendMail.Model.TipoCanale.MAIL,
                                    "0",
                                    msg,
                                    MySecurityProvider.CurrentPrincipal.MyIdentity.UserName, 2, "O");
                            if (c.MailComunicazione.MailRefs != null && c.MailComunicazione.MailRefs.Count != 0)
                            {
                                c.RubricaEntitaUsed = (from cont in c.MailComunicazione.MailRefs
                                                       select new SendMail.Model.ComunicazioniMapping.RubrEntitaUsed
                                {
                                    Mail = cont.MailDestinatario,
                                    TipoContatto = cont.TipoRef
                                }).ToList();
                            }
                            if (SessionManager <Dictionary <string, DTOFileUploadResult> > .exist(SessionKeys.DTO_FILE))
                            {
                                Dictionary <string, DTOFileUploadResult> dictDto = SessionManager <Dictionary <string, DTOFileUploadResult> > .get(SessionKeys.DTO_FILE);

                                List <DTOFileUploadResult> dto = (List <DTOFileUploadResult>)dictDto.Values.ToList();
                                c.ComAllegati = new List <ComAllegato>();
                                foreach (DTOFileUploadResult dd in dto)
                                {
                                    ComAllegato allegato = new SendMail.Model.ComunicazioniMapping.ComAllegato();
                                    allegato.AllegatoExt  = dd.Extension;
                                    allegato.AllegatoFile = dd.CustomData;
                                    allegato.AllegatoName = dd.FileName;
                                    allegato.AllegatoTpu  = "";
                                    allegato.FlgInsProt   = AllegatoProtocolloStatus.FALSE;
                                    allegato.FlgProtToUpl = AllegatoProtocolloStatus.FALSE;
                                    c.ComAllegati.Add(allegato);
                                }
                            }
                            foreach (MimePart mm in msg.Attachments)
                            {
                                if (mm.BinaryContent != null || mm.BinaryContent.Length > 10)
                                {
                                    if (c.ComAllegati == null)
                                    {
                                        c.ComAllegati = new List <ComAllegato>();
                                    }

                                    ComAllegato allegato = new SendMail.Model.ComunicazioniMapping.ComAllegato();
                                    FileInfo    info     = new FileInfo(mm.Filename);
                                    allegato.AllegatoExt  = info.Extension;
                                    allegato.AllegatoFile = mm.BinaryContent;
                                    allegato.AllegatoName = mm.Filename;
                                    allegato.AllegatoTpu  = "";
                                    allegato.FlgInsProt   = AllegatoProtocolloStatus.FALSE;
                                    allegato.FlgProtToUpl = AllegatoProtocolloStatus.FALSE;
                                    c.ComAllegati.Add(allegato);
                                }
                            }
                            comunicazioniService.InsertComunicazione(c);
                        }
                        catch (Exception ex)
                        {
                            ManagedException mex = new ManagedException("Errore nel salvataggio della mail",
                                                                        "MAIL_CMP_002", "", ex.StackTrace, ex);
                            ErrorLog err = new ErrorLog(mex);
                            log.Error(err);
                            model.message = "Errore nell'invio del messaggio";
                            model.success = "false";
                            return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model));
                        }
                    }
                    else
                    {
                        f.sendMail(msg);
                    }

                    model.message = "Email memorizzata correttamente";
                    model.success = "true";
                    return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model));
                }
                else
                {
                    model.message = "Account inesistente";
                    model.success = "false";
                    return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model));
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(ManagedException))
                {
                    log.Error(new Com.Delta.Logging.Errors.ErrorLog(new ManagedException(ex.Message, "FAC_007", string.Empty, string.Empty, ex)));
                }

                model.message = ex.Message;
                model.success = "false";
                return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model));
            }
            model.message = "Email memorizzata correttamente";
            model.success = "true";
            return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model));
        }