private void Send(string pProtocolName, string pMailServiceHost, string pMailAddress, string pPassword, Shared.MailMessage pMailMessage)
        {
            //se obtienen los datos del protocolo
            IProtocol mProtocol = this.iMailServiceRepository
                                  .Single(MailServiceSelector.ByName(pMailServiceHost))
                                  .Protocols.Single(bProtocol => bProtocol.Name.ToLower() == pProtocolName);

            //se configura el cliente y se envía el correo
            new Smtp(mProtocol).Send(pMailAddress, pPassword, pMailMessage);
        }
        private IEnumerable <System.Net.Mail.MailMessage> Retrieve(string pProtocolName, string pMailServiceHost, string pMailAddress, string pPassword, int pOffset = 0, int pWindow = 0)
        {
            //se obtienen los datos del protocolo
            IProtocol mProtocol = this.iMailServiceRepository
                                  .Single(MailServiceSelector.ByName(pMailServiceHost))
                                  .Protocols.Single(bProtocol => bProtocol.Name.ToLower() == pProtocolName);

            return(new Pop3(mProtocol).Retrieve(pMailAddress,
                                                pPassword,
                                                pOffset,
                                                pWindow));
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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
            {
            }
        }