public List <string> sendActivatedToGraduates(List <FullGraduateDto> graduateDtos, int userId)
        {
            UserDto        user    = UserManager.UserById(userId);
            MailConnection mail    = new MailConnection(user.email, byEmail, password);
            List <string>  errLine = new List <string>();

            foreach (var graduate in graduateDtos)
            {
                try
                {
                    mail.sendMessageToGraduates(
                        graduate.email,
                        "הצטרפות למחלקת השמה",
                        Activated(graduate.Id, graduate.firstName, graduate.linkToCV != null, user.name)
                        );
                }
                catch (Exception)
                {
                    errLine.Add($"{graduate.firstName} {graduate.lastName}");
                }
            }
            if (errLine.Count == graduateDtos.Count)
            {
                throw new Exception();
            }
            return(errLine);
        }
        public List <CoordinatingJobsForGraduates> sendjobOfferToGraduates(List <CoordinatingJobsForGraduates> coordinatingJob, int userId)
        {
            UserDto        user = UserManager.UserById(userId);
            MailConnection mail = new MailConnection(user.email, byEmail, password);
            List <CoordinatingJobsForGraduates> errLine = new List <CoordinatingJobsForGraduates>();

            foreach (var crd in coordinatingJob)
            {
                try
                {
                    mail.sendMessageToGraduates(
                        crd.Graduate.email,
                        crd.Job.title,
                        jobOffer(
                            Regex.Replace(crd.Job.description, @"\r\n?|\n", "<br/>"),
                            crd.candidateId,
                            crd.Graduate.firstName,
                            crd.Graduate.linkToCV != null,
                            crd.Id,
                            user.name)
                        );
                }
                catch (Exception)
                {
                    errLine.Add(crd);
                }
            }
            if (errLine.Count == coordinatingJob.Count)
            {
                throw new Exception();
            }
            return(errLine);
        }
        public override void Open()
        {
            base.Open();
            MailConnection.EmailStreamReader = new StreamReader(MailConnection.TcpClient.GetStream());
            MailConnection.EmailStream       = MailConnection.TcpClient.GetStream();
            LoggerHolders.ConsoleLogger.Log(MailConnection.EmailStreamReader.ReadLine());
            MailCommand command = MailConnection.CreateCommand();

            command.Command = "STARTTLS";
            command.ExecuteCommand();

            LoggerHolders.ConsoleLogger.Log(command.Response);

            var sslStrm = new SslStream(MailConnection.TcpClient.GetStream(), false);

            try
            {
                sslStrm.AuthenticateAsClient(MailConnection.Host);
            }
            catch (AuthenticationException ex)
            {
                LoggerHolders.ConsoleLogger.Log("Exception", LogType.Critical, ex);
                if (ex.InnerException != null)
                {
                    LoggerHolders.ConsoleLogger.Log("Exception", LogType.Critical, ex.InnerException);
                }
                MailConnection.TcpClient.Close();
            }

            MailConnection.EmailStream       = sslStrm;
            MailConnection.EmailStreamReader = new StreamReader(sslStrm);
        }
Exemplo n.º 4
0
        public MailOperation(MailConnection connection, IParameters parameters)
            : base(string.Empty, string.Empty)
        {
            _connection = connection;
            _parameters = parameters;

            _hasCc = parameters.ContainsName("cc");
            _ccKey = _hasCc ? parameters.GetKeyByName("cc") : string.Empty;

            _hasBcc = parameters.ContainsName("bcc");
            _bccKey = _hasBcc ? parameters.GetKeyByName("bcc") : string.Empty;

            _hasSubject = parameters.ContainsName("subject");
            _subjectKey = _hasSubject ? parameters.GetKeyByName("subject") : string.Empty;

            if (!parameters.ContainsName("from"))
            {
                throw new TransformalizeException(Logger, EntityName, "Mail transform requires parameter named from.");
            }
            _fromKey = parameters.GetKeyByName("from");

            if (!parameters.ContainsName("to"))
            {
                throw new TransformalizeException(Logger, EntityName, "Mail transform requires parameter named to.");
            }
            _toKey = parameters.GetKeyByName("to");

            if (!parameters.ContainsName("body"))
            {
                throw new TransformalizeException(Logger, EntityName, "Mail transform requires parameter named body.");
            }
            _bodyKey = parameters.GetKeyByName("body");

            Name = "Mail";
        }
Exemplo n.º 5
0
        public void OkCommand(object ownerWindow)
        {
            MailProviderFactory emailFactory = null;

            switch (_selectedReceiveConfiguration.Protocol)
            {
            case EmailProtocolType.Imap:
                emailFactory = new ImapProviderFactory();
                break;

            case EmailProtocolType.Pop3:
                emailFactory = new Pop3ProviderFactory();
                break;

            default:
                break;
            }

            MailConnection connection = emailFactory.CreateConnection();

            connection.Host = _selectedReceiveConfiguration.Host;
            connection.IsSslAuthentication = _selectedReceiveConfiguration.IsSslAuthentication;
            connection.Port = _selectedReceiveConfiguration.Port;
            ////connection.Open();
            SslMailConnectionDecorator sslMailConnectionDecorator = new SslMailConnectionDecorator();

            sslMailConnectionDecorator.MailConnection = connection;
            sslMailConnectionDecorator.Open();
            MailClient client = emailFactory.CreateClient();

            client.Authenticate(new MailUserInfo()
            {
                Email = _login, Password = _securePassword
            });

            new MainWindow()
            {
                DataContext = new MainWindowVM(client)
            }.Show();
            ((Window)ownerWindow).Close();
        }
        public List <FullGraduateDto> sendCVCandidateToContact(string title, string massege, List <FullGraduateDto> graduates, string contactMail, int userId)
        {
            UserDto                user      = UserManager.UserById(userId);
            MailConnection         mail      = new MailConnection(user.email, byEmail, password);
            List <FullGraduateDto> disSendCV =
                mail.sendCVtoContact(
                    contactMail,
                    "מועמדים המרכז החרדי למשרה " + title,
                    $@"
                    <head>
                        <style>
                            {fontStyle}
                      </style>
                    </head>
                    <div class='text'>{massege}</div>",
                    graduates,
                    host);

            if (disSendCV.Count == graduates.Count)
            {
                throw new Exception();
            }
            return(disSendCV);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            string        result = "";
            string        url    = @"http://*****:*****@gmail.com", Password = securePass });



            MailCommand command = client.Connection.CreateCommand();

            command.Command = "AUTHENTICATE XOAUTH DQAAAA0BAACM5VezEB1fG75L4oTHjEnfHS-YuSLBUe_OKL9QFCcgxqP7SLkk_6AFgCqFdNWnId_ohkmTShCeb5rkgdZR5zceaMoIPDyCY4rWkyMjY8S-2vmkXSgHLUTmhZyZLPT3j7rAnEou-QEdHxjKpqiZ8a04QiOqvhIOWmN9JEWBxSYqdM5eIH8xG4pz19c6TWUhq1PJCYCyNsU384uNyFanJ-tg0z9c1dF1mgqLscbYZz82RKsZAPyu9Um2VrWWSW9r_56_OW7JJT709cte1jx0h29HEhF5J_4LZ1Md5bGHUFJQPS7-gJBLJApaVxWZfhpc_r19sNzaqdZYsIuUxRM65jiYXPomvozXSK4ASonS1cXu3g";
            command.ExecuteCommand();
            LoggerHolders.ConsoleLogger.Log(command.Response);
            command.Command = "RETR 300";
            command.ExecuteCommand(true);
            LoggerHolders.ConsoleLogger.Log(command.Response);
            StreamWriter writer = new StreamWriter(@"C:\fetch.log");

            writer.Write(command.Response);
            writer.Close();



            //MailProviderFactory emailFactory = new ImapProviderFactory();
            //MailConnection connection = emailFactory.CreateConnection();
            ////connection.Host = config.Imap.Host;
            ////connection.IsSslAuthentication = config.Imap.IsSslAuthentication;
            ////connection.Port = config.Imap.Port;
            ////connection.SecureTypeConnection = new SslMailConnection();
            //connection.Host = "imap.mail.ru";
            //connection.IsSslAuthentication = true;
            //connection.Port = 143;
            //SecureMailConnectionDecorator sslMailConnection = new TlsMailConnectionDecorator();
            //sslMailConnection.MailConnection = connection;
            //sslMailConnection.Open();
            //MailClient client = emailFactory.CreateClient();
            //client.Authenticate(new MailUserInfo() { Email = "*****@*****.**", Password = securePass });

            //connection.Host = "imap.mail.ru";
            //connection.IsSslAuthentication = true;
            //connection.Port = 143;
            //connection.Open();
            //MailClient client = emailFactory.CreateClient();
            //MailCommand com = client.Connection.CreateCommand();
            //com.Command = "STARTTLS";
            //com.ExecuteCommand();

            //var ssl = client.Connection._tcpClient.GetStream();
            //client.Connection._emailStream = ssl;
            //client.Connection._emailsStreamReader = new StreamReader(ssl);
            //Console.WriteLine(client.Connection._emailsStreamReader.ReadLine());



            //Thread.Sleep(5000);

            //com.Command = "CAPABILITY";
            //com.ExecuteCommand();



            //LoggerHolders.ConsoleLogger.Log(com.Response, LogType.Debug);


            //client.Authenticate(new MailUserInfo() { Email = "*****@*****.**", Password = securePass });
            //com.Command = "AUTH PLAIN";
            //com.ExecuteCommand();

            //////MailCommand command = client.Connection.CreateCommand();
            ////////command.Command = "STATUS INBOX (messages)";
            ////////command.ExecuteCommand();
            ////////LoggerHolders.ConsoleLogger.Log(command.Response);

            //////command.Command = "SELECT INBOX";
            //////command.ExecuteCommand();
            //////LoggerHolders.ConsoleLogger.Log(command.Response);

            //////command.Command = "FETCH " + 5343 + " (body[header.fields (from subject date)])";
            //////command.ExecuteCommand();
            //////LoggerHolders.ConsoleLogger.Log(command.Response, LogType.Debug);
            ///
            ///
            ///



            //StreamReader readerHeader = new StreamReader(@"C:\header.txt");

            //string header = readerHeader.ReadToEnd();
            //readerHeader.Close();
            //LoggerHolders.ConsoleLogger.Log(header, LogType.Info);

            ////string pat =
            ////    @"Subject: (?<encodedName>(=\?[A-Za-z0-9-]+\?(B|Q|b|q)\?.+\?=[\s]*)+)";

            ////Regex regex = new Regex(pat);
            ////Match match = regex.Match(header);

            ////Console.WriteLine(match.Groups["encodedName"].Value);

            //IMailMessageBuilder builder = new ReceiveMailMessageBuilder(header);
            //MailMessageDirector director = new MailMessageDirector(builder);
            //director.ConstructMailMessage();
            //MailMessage messageHeader = builder.GetMailMessage();
            //LoggerHolders.ConsoleLogger.Log(string.Format("From: {0} <{1}>\nSubject: {2}\nDate: {3}\n{4}",
            //    messageHeader.FromName, messageHeader.From, messageHeader.Subject, messageHeader.Date,
            //    messageHeader.DateLocal), LogType.Debug);

            Console.ReadLine();
        }
Exemplo n.º 8
0
 public EmailSink(TflLog log)
 {
     _log  = log;
     _mail = (MailConnection)log.ConnectionInstance;
 }