Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)//sender
        {
            string appSign = "UrfaDiyarbakir";


            if (listBox1.SelectedIndex >= 0)
            {
                char[] charsToTrim = { ' ', '"' };
                int    index       = listBox1.SelectedIndex;
                var    dateTime    = DateTime.Now;
                string mailfrom    = logformobj.getUsrName();
                string mailpass    = logformobj.getUsrPass();
                try
                {
                    string encryptedAESkey = friends[index, 0].Trim(charsToTrim);
                    string decryptedAESkey = RSAobj.Decrypt(encryptedAESkey);
                    string mailTo          = friends[index, 2].Trim(charsToTrim);
                    var    post            = new MailMessage(mailfrom, mailTo);
                    string MailSign        = textBox1.Text + "\n" + dateTime;
                    string cryptedMailSign = RSAobj.SignData(MailSign);
                    post.Subject = AesCrypt.EncryptParam(textBox2.Text, decryptedAESkey);
                    post.Body    = AesCrypt.Encrypt(appSign) + "---AppSign---" + AesCrypt.Encrypt(EncryptedMailApp.LoginForm.user) + "---Username---" + AesCrypt.EncryptParam(textBox1.Text + "\n" + dateTime, decryptedAESkey) + "---Body---" + cryptedMailSign + "---Sign---";
                    ;

                    using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
                    {
                        smtp.Credentials = new NetworkCredential(mailfrom, mailpass);
                        smtp.EnableSsl   = true;
                        if (!string.IsNullOrEmpty(textBox3.Text))
                        {
                            EncryptedMailApp.CryptoStuff.EncryptFile(password, textBox3.Text, textBox3.Text + "crp");
                            Attachment data = new Attachment(textBox3.Text + "crp");
                            post.Attachments.Add(data);
                            smtp.Send(post);
                            MessageBox.Show("Email Sent With Attachment");
                        }
                        else
                        {
                            smtp.Send(post);
                            MessageBox.Show("Email Sent");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("ERROR");
                }
            }
            else
            {
                MessageBox.Show("There is no selected friend!");
            }
        }