示例#1
0
        public static MailMessage SendMail(mess Mess)
        {
            try
            {
                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                mail.From = new System.Net.Mail.MailAddress(MyInfo.userName);
                mail.To.Add(new System.Net.Mail.MailAddress(Mess.To));
                mail.Subject = Mess.Subject;
                mail.Body    = Mess.Body;

                SmtpClient client = new SmtpClient();

                client.Host                  = "smtp.gmail.com";
                client.Port                  = 587;
                client.EnableSsl             = true;
                client.UseDefaultCredentials = true;
                client.Credentials           = new NetworkCredential(MyInfo.userName, MyInfo.password);
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                client.Send(mail);
                return(mail);
            }
            catch (Exception e)
            {
                throw new Exception("Mail.Send: " + e.Message);
            }
        }
示例#2
0
        private void send_mail_Click(object sender, RoutedEventArgs e)
        {
            string encryptedMessage = null;
            bool   isEncrypted      = false;

            if (this.Encrypt_Sign.IsChecked == true)
            {
                isEncrypted = true;
                if (string.IsNullOrEmpty(pass) || string.IsNullOrEmpty(pubKey))
                {
                    MessageBox.Show("Please enter encryption paramaters first", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                try
                {
                    encryptedMessage = Crypto.Encryption.EncryptAndSignMessage(body.Text, pubKey, pass);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else if (this.Encrypt.IsChecked == true)
            {
                isEncrypted = true;
                if (string.IsNullOrEmpty(pubKey))
                {
                    MessageBox.Show("Please enter encryption paramaters first", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                try
                {
                    encryptedMessage = Crypto.Encryption.EncryptMessage(body.Text, pubKey);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            mess Mess = new mess();

            Mess.From    = MyInfo.userName;
            Mess.To      = to.Text;
            Mess.Subject = subject.Text;
            Mess.Body    = (isEncrypted) ? encryptedMessage : body.Text;
            EmailHelper.SendMail(Mess); // mesage sent
            MessageBox.Show("Email has been sent");
            this.Close();
        }