Пример #1
0
        private void _bSendMessage_Click(object sender, EventArgs e)
        {
            this.AddLogEntry("Creating message.");

            // We create the message object
            ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();

            try
            {
                // We assign the sender email
                message.From.Email = this._tbFromEmail.Text;

                // We assign the recipient email
                message.To.Add(this._tbToEmail.Text);

                // We assign the subject
                message.Subject = this._tbSubject.Text;

                // We assign the body text
                message.BodyText.Text = this._tbBodyText.Text;

                // It is required to build the mime part tree before encrypting
                message.BuildMimePartTree();

                // Encrypt the message. You need the recipient(s) certificate(s) (with public key only).
                X509Certificate2 recipientCertificate = new X509Certificate2(_tbRecipientCertificate.Text);

                CmsRecipient recipient = new CmsRecipient(recipientCertificate);

                message.SmimeEnvelopeAndEncryptFor(recipient);

                // We send the email using the specified SMTP server
                this.AddLogEntry("Sending message.");

                message.Send(this._tbSmtpServer.Text);

                this.AddLogEntry("Message sent successfully.");
            }

            catch (SmtpException ex)
            {
                this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }
        private void _bSendMessage_Click(object sender, EventArgs e)
        {
            this.AddLogEntry("Creating message.");

            // We create the message object
            ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();

            try
            {
                // We assign the sender email
                message.From.Email = this._tbFromEmail.Text;

                // We assign the recipient email
                message.To.Add(this._tbToEmail.Text);

                // We assign the subject
                message.Subject = this._tbSubject.Text;

                // We assign the body text
                message.BodyText.Text = this._tbBodyText.Text;

                // It is required to build the mime part tree before encrypting
                message.BuildMimePartTree();

                // Encrypt the message. You need the recipient(s) certificate(s) (with public key only).
                X509Certificate2 recipientCertificate = new X509Certificate2(_tbRecipientCertificate.Text);

                CmsRecipient recipient = new CmsRecipient(recipientCertificate);

                message.SmimeEnvelopeAndEncryptFor(recipient);

                // We send the email using the specified SMTP server
                this.AddLogEntry("Sending message.");
                           
                message.Send(this._tbSmtpServer.Text);

                this.AddLogEntry("Message sent successfully.");
            }

            catch (SmtpException ex)
            {
                this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }