Beispiel #1
0
        //-----------------------------------------------------------------------------------------------------------
        /// <summary>
        /// FTPs the send.
        /// </summary>
        /// <param name="ftpInfo">The FTP info.</param>
        /// <param name="filesToUpload">The files to upload.</param>
        public void FTPSend(FTPInfo ftpInfo, List <string> filesToUpload)
        {
            this.ftpInfo = ftpInfo;

            try
            {
                if (ftpInfo.ProtectPassword)
                {
                    ftpInfo.Password = OperationUtils.EncryptDecrypt(ftpInfo.Password);
                }

                foreach (string file in filesToUpload)
                {
                    CreateRecursiveFTPFolder();

                    Stream requestStream = UploadFile(file);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (ftpInfo.ProtectPassword)
                {
                    ftpInfo.Password = OperationUtils.EncryptDecrypt(ftpInfo.Password);
                }
            }
        }
 public void UpdateUI()
 {
     textBox_SMTPServer.Text            = configManager.SmtpInfo.SmtpServer;
     textBox_UserName.Text              = configManager.SmtpInfo.UserName;
     textBox_Password.Text              = OperationUtils.EncryptDecrypt(configManager.SmtpInfo.Password);
     numericUpDown_PollingTimeout.Value = configManager.SmtpInfo.TimeOut;
     numericUpDown_port.Value           = configManager.SmtpInfo.Port;
     checkBox_EnableSSL.Checked         = configManager.SmtpInfo.SSL;
     checkBox_HTMLMode.Checked          = configManager.SmtpInfo.IsBodyHtml;
 }
Beispiel #3
0
 public void UpdateUI()
 {
     textBox_FTPServer.Text      = configManager.FtpInfo.FTPServer;
     textBox_User.Text           = configManager.FtpInfo.UserName;
     textBox_Password.Text       = OperationUtils.EncryptDecrypt(configManager.FtpInfo.Password);
     numericUpDown_port.Value    = configManager.FtpInfo.Port;
     checkBox_EnableSSL.Checked  = configManager.FtpInfo.SSL;
     textBox_DefaultFolder.Text  = configManager.FtpInfo.FTPServerFolder;
     numericUpDown_Timeout.Value = configManager.FtpInfo.TimeOut;
 }
Beispiel #4
0
 public void UpdateConfig()
 {
     configManager.FtpInfo.FTPServer       = textBox_FTPServer.Text;
     configManager.FtpInfo.UserName        = textBox_User.Text;
     configManager.FtpInfo.Password        = OperationUtils.EncryptDecrypt(textBox_Password.Text);
     configManager.FtpInfo.ProtectPassword = true;
     configManager.FtpInfo.Port            = decimal.ToInt32(numericUpDown_port.Value);
     configManager.FtpInfo.SSL             = checkBox_EnableSSL.Checked;
     configManager.FtpInfo.FTPServerFolder = textBox_DefaultFolder.Text;
     configManager.FtpInfo.TimeOut         = decimal.ToInt32(numericUpDown_Timeout.Value);
 }
        public void UpdateConfig()
        {
            configManager.SmtpInfo.SmtpServer = textBox_SMTPServer.Text;
            configManager.SmtpInfo.UserName   = textBox_UserName.Text;
            configManager.SmtpInfo.Password   = OperationUtils.EncryptDecrypt(textBox_Password.Text);
            configManager.SmtpInfo.TimeOut    = decimal.ToInt32(numericUpDown_PollingTimeout.Value);
            configManager.SmtpInfo.Port       = decimal.ToInt32(numericUpDown_port.Value);
            configManager.SmtpInfo.SSL        = checkBox_EnableSSL.Checked;
            configManager.SmtpInfo.IsBodyHtml = checkBox_HTMLMode.Checked;

            configManager.SmtpInfo.ProtectPassword = true;
        }
        //------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Send Emails using smtp settings
        /// </summary>
        /// <param name="transportInfo">The transport info.</param>
        /// <param name="emails">The emails.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="message">The message.</param>
        /// <param name="attachment">The attachments list. Send null in case there is no attachment</param>
        public void SmtpSend(SmtpInfo smtpInfo, List <string> toEmails, List <string> ccEmails, string subject, string message, List <string> attachments)
        {
            SmtpClient smtp = new SmtpClient();
            Attachment updatesAttachement = null;

            if (smtpInfo.ProtectPassword)
            {
                smtpInfo.Password = OperationUtils.EncryptDecrypt(smtpInfo.Password);
            }

            try
            {
                smtp.Credentials = new System.Net.NetworkCredential(smtpInfo.UserName, smtpInfo.Password);
                smtp.Host        = smtpInfo.SmtpServer;
                smtp.Port        = smtpInfo.Port;
                smtp.EnableSsl   = smtpInfo.SSL;
                smtp.Timeout     = smtpInfo.TimeOut;

                mail      = new MailMessage();
                mail.From = new MailAddress(smtpInfo.UserName);

                foreach (string toEmail in toEmails)
                {
                    if (toEmail != string.Empty)
                    {
                        mail.To.Add(toEmail);
                    }
                }

                if (ccEmails != null)
                {
                    foreach (string ccEmail in ccEmails)
                    {
                        if (ccEmail != string.Empty)
                        {
                            mail.CC.Add(ccEmail);
                        }
                    }
                }

                mail.Subject    = subject;
                mail.IsBodyHtml = smtpInfo.IsBodyHtml;
                mail.Body       = message;
                if (attachments != null)
                {
                    foreach (string attachment in attachments)
                    {
                        if (File.Exists(attachment))
                        {
                            updatesAttachement = new Attachment(attachment);
                            mail.Attachments.Add(updatesAttachement);
                        }
                        else
                        {
                            throw new ArgumentException("One or more attachment provided are not valid");
                        }
                    }
                }

                if (SendAsynchronous)
                {
                    smtp.SendCompleted += new SendCompletedEventHandler(smtp_SendCompleted);
                    smtp.SendAsync(mail, null);
                }
                else
                {
                    smtp.Send(mail);
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }
            finally
            {
                if (!SendAsynchronous)
                {
                    mail.Dispose();
                }
                if (smtpInfo.ProtectPassword)
                {
                    smtpInfo.Password = OperationUtils.EncryptDecrypt(smtpInfo.Password);
                }
                if (updatesAttachement != null)
                {
                    updatesAttachement.Dispose();
                }
            }
        }