示例#1
0
        public SmtpModel GetMailInfo()
        {
            string    connectionString = "server=localhost;uid=root;password=Reset1234;database=OnlineTestManagement;";
            SmtpModel model            = new SmtpModel();
            string    queryString      =
                "SELECT * FROM OnlineTestManagement.SmtpMail;";

            using (MySqlConnection connection =
                       new MySqlConnection(connectionString))
            {
                MySqlCommand command =
                    new MySqlCommand(queryString, connection);
                connection.Open();

                MySqlDataReader reader = command.ExecuteReader();

                // Call Read before accessing data.
                while (reader.Read())
                {
                    model.Id           = (int)reader[0];
                    model.FromMail     = reader[1].ToString();
                    model.SmtpPassword = reader[2].ToString();
                    model.Host         = reader[3].ToString();
                    model.Port         = reader[4].ToString();
                    model.DisplayName  = reader[5].ToString();
                    model.Description  = reader[6].ToString();
                }

                // Call Close when done reading.
                connection.Close();
            }

            return(model);
        }
        public void SendEmailTest(SmtpModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("SmtpMail ArgumentNullException Testing Async");
            }

            //Smtp dto = AutoMapperGenericHelper<SmtpModel, Smtp>.Convert(model);
            _smtpRepository.SendEmailTest(model);
        }
        public Task UpdateAsync(SmtpModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("Smtp ArgumentNullException Update Async");
            }

            Smtp dto = AutoMapperGenericHelper <SmtpModel, Smtp> .Convert(model);

            _smtpRepository.Update(dto);

            return(Task.FromResult <object>(null));
        }
示例#4
0
 public static bool WriteSmtp(SmtpModel model)
 {
     using (IDbConnection con = new SQLiteConnection(LoadConnectionString()))
     {
         con.Open();
         bool result = 1 == con.Execute(
             @"insert or ignore into Smtp (Smtp,Email,Password,Port,EnableSsl) VALUES (@Smtp,@Email,@Password,@Port,@EnableSsl)",
             new { model.Smtp, model.Email, model.Password, model.Port, model.EnableSsl },
             commandType: CommandType.Text);
         con.Close();
         return(result);
     }
 }
示例#5
0
        private void _ucSmtp_Load(object sender, EventArgs e)
        {
            smtp = DataAccess.ReadSmtp();

            if (smtp != null)
            {
                txtSmtp.Text  = smtp.Smtp;
                txtEmail.Text = smtp.Email;
                txtPass.Text  = smtp.Password;
                nupPort.Value = smtp.Port;
                cbSsl.Checked = smtp.UseSsl;
            }
        }
        public Task <object> InsertAsync(SmtpModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("Smtp ArgumentNullException Insert Async");
            }

            Smtp dto = AutoMapperGenericHelper <SmtpModel, Smtp> .Convert(model);

            var id = _smtpRepository.Insert(dto);

            return(Task.FromResult <object>(id));
        }
示例#7
0
        private void btnSaveSmtp_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSmtp.Text))
            {
                txtSmtp.Focus();
                return;
            }

            if (string.IsNullOrEmpty(txtEmail.Text))
            {
                txtEmail.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(txtPass.Text))
            {
                txtPass.Focus();
                return;
            }

            try
            {
                SmtpModel model = new SmtpModel();
                if (cbSsl.Checked)
                {
                    model.EnableSsl = 1;
                }
                model.Email    = txtEmail.Text;
                model.Password = txtPass.Text;
                model.Port     = (int)nupPort.Value;
                model.Smtp     = txtSmtp.Text;

                bool result = DataAccess.WriteSmtp(model);

                if (result)
                {
                    MessageHelper.DisplayDone(Translation.General.Saved);
                }
                else
                {
                    MessageHelper.DisplayError(Translation.General.CantSaveSMTP);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                throw;
            }
        }
        public Task <SmtpModel> GetAsync(int id)
        {
            var dal = _smtpRepository.Get(id);

            if (dal == null)
            {
                return(Task.FromResult <SmtpModel>(null));
            }
            else
            {
                SmtpModel model = AutoMapperGenericHelper <Smtp, SmtpModel> .Convert(dal);

                return(Task.FromResult(model));
            }
        }
示例#9
0
        /// <summary>
        /// Get the smtp host.
        /// </summary>
        /// <param name="section">The config section group and section name.</param>
        /// <returns>The smtp model.</returns>
        /// <exception cref="System.Exception">Configuration load exception is thrown.</exception>
        public SmtpModel GetSmtpHost(string section = "NequeoMailGroup/NequeoNetMail")
        {
            SmtpModel encoder = null;

            try
            {
                // Refreshes the named section so the next time that it is retrieved it will be re-read from disk.
                System.Configuration.ConfigurationManager.RefreshSection(section);

                // Create a new default host type
                // an load the values from the configuration
                // file into the default host type.
                WebMail defaultEncoder =
                    (WebMail)System.Configuration.ConfigurationManager.GetSection(section);

                // Make sure the section is defined.
                if (defaultEncoder == null)
                {
                    throw new Exception("Configuration section has not been defined.");
                }

                // Get the encoder element.
                SmtpElement encoderElement = defaultEncoder.SmtpSection;
                if (encoderElement == null)
                {
                    throw new Exception("Configuration element Smtp has not been defined.");
                }

                // Create an instance of the encoder type.
                EmailerConnectionAdapter adapter = new EmailerConnectionAdapter(encoderElement.Host, encoderElement.Port);
                adapter.UserName = encoderElement.Username;
                adapter.Password = encoderElement.Password;

                // Create the smtp model.
                encoder         = new SmtpModel();
                encoder.Adapter = adapter;
                encoder.From    = encoderElement.From;
            }
            catch (Exception)
            {
                throw;
            }

            // Return the encoder.
            return(encoder);
        }
        public IHttpActionResult Patch(SmtpModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                _smtpService.UpdateAsync(model);
                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#11
0
 public IActionResult DeleteSmtp(int id)
 {
     if (ModelState.IsValid)
     {
         var model = new SmtpModel();
         try
         {
             var provider = model.Delete(id);
             model.Response = new ResponseModel($"Smtp {provider} successfully deleted.", ResponseType.Success);
             return(RedirectToAction("Index"));
         }
         catch (Exception ex)
         {
             model.Response = new ResponseModel("Smtp delete failued.", ResponseType.Failure);
             // error logger code
         }
     }
     return(RedirectToAction("index"));
 }
示例#12
0
        public void SendEmailTest(SmtpModel model)
        {
            MailMessage msg = new MailMessage();

            if (model.DefaultTo != "" && model.DefaultTo != null)
            {
                msg.To.Add(new MailAddress(model.DefaultTo.Trim()));
            }

            string sendFromEmail    = model.UserMail;
            string sendFromPassword = model.UserPw;

            msg.From       = new MailAddress(sendFromEmail);
            msg.Subject    = "Test Mesajı";
            msg.Body       = "Bu mail Smtp test amaçlı atılmıştır.";
            msg.IsBodyHtml = true;
            SmtpClient client = new SmtpClient(model.SmtpHost);

            client.Port                  = model.SmtpPort;
            client.EnableSsl             = true;
            client.UseDefaultCredentials = false;
            NetworkCredential cred = new NetworkCredential(sendFromEmail, sendFromPassword);

            client.Credentials    = cred;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

            try
            {
                client.Send(msg);
                msg.Dispose();
            }
            catch (Exception e)
            {
                e.ToString();
            }
        }
示例#13
0
        public void SendMail(EmailModel model)
        {
            var       smtpailObj = Get(1);
            SmtpModel obj        = AutoMapperGenericHelper <Smtp, SmtpModel> .Convert(smtpailObj);


            MailMessage msg = new MailMessage();

            if (obj != null)
            {
                //gelen string list e göre alıcıları msg a ekler.
                if (model.Recipient != null)
                {
                    foreach (string currentEmailAddress in model.Recipient)
                    {
                        msg.To.Add(new MailAddress(currentEmailAddress.Trim()));
                    }
                }
                else
                {
                    //gelen yoksa default kullanıcıyı ekler.
                    msg.To.Add(new MailAddress(obj.DefaultTo.Trim()));
                }
                //filename ve filecontent dictionary den okunup attachment olarak eklenir
                if (model.dictionaryMail != null && model.dictionaryMail.Keys.Count() > 0)
                {
                    foreach (KeyValuePair <string, byte[]> entry in model.dictionaryMail)
                    {
                        Attachment attc = new Attachment(new MemoryStream(entry.Value), entry.Key);
                        msg.Attachments.Add(attc);
                    }
                }


                string sendFromEmail    = obj.UserMail;
                string sendFromPassword = obj.UserPw;

                msg.From       = new MailAddress(sendFromEmail);
                msg.Subject    = model.Subject;
                msg.Body       = model.Body;
                msg.IsBodyHtml = true;
                SmtpClient client = new SmtpClient(obj.SmtpHost);
                client.Port                  = obj.SmtpPort;
                client.EnableSsl             = true;
                client.UseDefaultCredentials = false;
                NetworkCredential cred = new NetworkCredential(sendFromEmail, sendFromPassword);
                client.Credentials    = cred;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

                try
                {
                    client.Send(msg);
                    msg.Dispose();
                }
                catch (Exception e)
                {
                    e.ToString();
                }
            }
        }
示例#14
0
        public NotificationService()
        {
            _connection                 = new Connection();
            emailVerificationQueues     = new Queue <EmailVerificationQueueModel>();
            emailVerificationLockObject = new object();

            passwordQueues     = new Queue <PasswordQueueModel>();
            passwordLockObject = new object();

            eventQueues     = new Queue <EventQueueModel>();
            eventLockObject = new object();

            eventParticipantRequestQueues = new Queue <EventParticipantRequestQueueModel>();
            eventParticipantLockObject    = new object();

            HubConnection connection = new HubConnectionBuilder().WithUrl(_connection.apiUrl + "/NotificationHub").Build();

            connection.StartAsync().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine(task.Exception);
                }
                else
                {
                    Console.WriteLine("SignalR Connected...");
                }
            });

            connection.On <EventQueueModel>("sendEventPushNotification", (item) =>
            {
                eventQueues.Enqueue(item);
            });

            connection.On <EmailVerificationQueueModel>("SendEmailVerification", (item) =>
            {
                emailVerificationQueues.Enqueue(item);
            });

            connection.On <PasswordQueueModel>("SendPassword", (item) =>
            {
                passwordQueues.Enqueue(item);
            });

            connection.On <EventParticipantRequestQueueModel>("sendEventParticipantRequest", (item) =>
            {
                eventParticipantRequestQueues.Enqueue(item);
            });

            emailVerificaitonTimer = new Timer(EmailVerificationTick, emailVerificationLockObject, TimeSpan.Zero, TimeSpan.FromSeconds(15));
            passwordTimer          = new Timer(PasswordTick, passwordLockObject, TimeSpan.Zero, TimeSpan.FromSeconds(15));
            eventTimer             = new Timer(EventTick, eventLockObject, TimeSpan.Zero, TimeSpan.FromSeconds(15));
            eventParticipantTimer  = new Timer(EventParticipantTick, eventParticipantLockObject, TimeSpan.Zero, TimeSpan.FromSeconds(60));

            _SSystemParameter  = new SSystemParameter(new DbContext());
            _SMethod           = new SMethod();
            _SEvent            = new SEvent(new DbContext());
            _SEventParticipant = new SEventParticipant(new DbContext());
            _SUser             = new SUser(new DbContext());


            List <SystemParameter> systemParameters = _SSystemParameter.GetSystemParameter();
            SmtpModel smtpModel = _SMethod.SystemParameterToObject <SmtpModel>(systemParameters);

            if (!String.IsNullOrEmpty(smtpModel.smtp_host))
            {
                _SSmtp = new SSmtp(smtpModel.smtp_host, smtpModel.smtp_port, smtpModel.smtp_sender, smtpModel.smtp_password);
            }
        }
 public MailService(IOptions <SmtpModel> smtpModel)
 {
     _smtpmodel = smtpModel.Value;
 }
示例#16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="smtp"></param>
 public EmailHelper(SmtpModel smtp)
 {
     Smtp = smtp;
 }
示例#17
0
 public void Config(SmtpModel smtpModel, MailMessage mailMessage)
 {
     this.smtpModel   = smtpModel;
     this.mailMessage = mailMessage;
 }