Exemplo n.º 1
0
        public void Send(int pMailAccountId, string pProtocolName, IEnumerable <string> pToMailAddresses, string pSubject, string pBody)
        {
            try
            {
                //se obtiene la cuenta del usuario activo
                MailAccount mMailAccount = this.iMailAccountRepository.Single(MailAccountSelector.ById(pMailAccountId));

                //se crea el mensaje
                MailMessage mMailMessage = new Shared.MailMessage()
                {
                    Subject = pSubject,
                    To      = pToMailAddresses.Select(bMailAddress => new Shared.MailAddress()
                    {
                        Value = bMailAddress
                    }).ToList(),
                    Body = pBody
                };

                mMailMessage.From = mMailAccount.MailAddress;
                //guardar el mensaje en el repositorio
                mMailAccount.MailAddress.FromMessages.Add(mMailMessage);
                mMailMessage.To       = this.ResolveDbMailAddresses(mMailMessage.To).ToList();
                mMailMessage.DateSent = DateTime.Now.ToShortDateString();
                MCDAL.Instance.Save();

                this.Send(pProtocolName, mMailAccount.GetMailServiceHost(), mMailAccount.MailAddress.Value, this.iEncryptor.Decrypt(mMailAccount.Password), mMailMessage);
            }
            catch (Exception bException)
            {
                throw new FailOnSend(Resources.Exceptions.MailService_Send_FailOnSend, bException);
            }
        }
Exemplo n.º 2
0
        public void Execute(int pMailAccountId, string pProtocolName, IEnumerable <string> pToMailAddresses, string pSubject, string pBody)
        {
            try
            {
                //se obtiene la cuenta del usuario activo
                this.iMailAccount = this.iMailAccountRepository.Single(MailAccountSelector.ById(pMailAccountId));

                //se crea el mensaje
                this.iMailMessage = new Shared.MailMessage()
                {
                    Subject = pSubject,
                    To      = pToMailAddresses.Select(bMailAddress => new Shared.MailAddress()
                    {
                        Value = bMailAddress
                    }).ToList(),
                    Body = pBody
                };

                //se obtienen los datos del protocolo
                this.iProtocol = this.iMailServiceRepository
                                 .Single(MailServiceSelector.ByName(this.iMailAccount.GetMailServiceHost()))
                                 .Protocols.Single(bProtocol => bProtocol.Name.ToLower() == pProtocolName);

                iMailMessage.From = iMailAccount.MailAddress;
                //guardar el mensaje en el repositorio
                iMailAccount.MailAddress.FromMessages.Add(iMailMessage);
                iMailMessage.To = this.ResolveDbMailAddresses(iMailMessage.To).ToList();
                MCDAL.Instance.Save();

                this.Send(iMailAccount.MailAddress.Value, this.iEncryptor.Decrypt(iMailAccount.Password), iMailMessage);
            }
            catch (Exception bException)
            {
                throw new FailOnSend(Resources.Exceptions.MailService_Send_FailOnSend, bException);
            }
        }
Exemplo n.º 3
0
        public void Execute(int pMailAccountId, string pProtocolName, int pRetrieveWindowSize)
        {
            try
            {
                //se obtiene la cuenta del usuario activo
                this.iMailAccount        = this.iMailAccountRepository.Single(MailAccountSelector.ById(pMailAccountId));
                this.iRetrieveWindowSize = pRetrieveWindowSize;

                //se obtienen los datos del protocolo
                this.iProtocol = this.iMailServiceRepository
                                 .Single(MailServiceSelector.ByName(this.iMailAccount.GetMailServiceHost()))
                                 .Protocols.Single(bProtocol => bProtocol.Name.ToLower() == pProtocolName);

                //se obtiene la cantidad de mensajes como base para obtener los siguientes
                int mLastMessageId =
                    this.iMailAccount.MailAddress.FromMessages.Any() &&
                    this.iMailAccount.MailAddress.ToMessages.Any()
                        ? this.iMailAccount.MailAddress.FromMessages.Union(this.iMailAccount.MailAddress.ToMessages).Count()
                        : 0;

                //se obtienen los correos
                IEnumerable <MailMessage> mMailMessages =
                    this.Retrieve(this.iMailAccount.GetMailServiceHost(),
                                  this.iMailAccount.MailAddress.Value,
                                  this.iEncryptor.Decrypt(this.iMailAccount.Password),
                                  mLastMessageId,
                                  this.iRetrieveWindowSize)
                    .Select(bMailMessage => bMailMessage.ToMailClientMailMessage())
                    .ToList();

                //para los mensajes que tienen como remitente el correo del usuario
                // y que no existan en la bbdd
                IEnumerable <MailMessage> mFromListMessage =
                    mMailMessages
                    .Where(bMessage => bMessage.From.Value.Equals(this.iMailAccount.MailAddress.Value))
                    .Where(bMessage => !this.iMailAccount.MailAddress.FromMessages.Any(bSendedMessage => bSendedMessage.ExternalId == bMessage.ExternalId));

                //se agrega cada mensaje a la bbdd
                foreach (MailMessage bMailMessage in mFromListMessage)
                {
                    bMailMessage.From = this.iMailAccount.MailAddress;
                    bMailMessage.To   = this.ResolveDbMailAddresses(bMailMessage.To).ToList();
                    this.iMailAccount.MailAddress.FromMessages.Add(bMailMessage);
                    MCDAL.Instance.Save();
                }

                //para los mensajes que no tienen como remitente el correo del usuario
                IEnumerable <MailMessage> mRecivedMailMessages =
                    mMailMessages
                    .Where(bMessage => !bMessage.From.Value.Equals(this.iMailAccount.MailAddress.Value))
                    .Where(bMessage => !this.iMailAccount.MailAddress.ToMessages.Any(bSendedMessage => bSendedMessage.ExternalId == bMessage.ExternalId));


                //se agrega cada mensaje a la bbdd
                foreach (MailMessage bMailMessage in mRecivedMailMessages)
                {
                    bMailMessage.From = this.iMailAddressRepository.Single(MailAddressSelector.ByMailAddress(bMailMessage.From.Value)) ?? bMailMessage.From;
                    bMailMessage.To   = this.ResolveDbMailAddresses(bMailMessage.To).ToList();
                    this.iMailAccount.MailAddress.ToMessages.Add(bMailMessage);
                    MCDAL.Instance.Save();
                }
            }
            catch
            {
            }
        }