コード例 #1
0
        /*
         * Button btnCancelar action
         */
        private void btnCancelar_Click(object sender, EventArgs e)
        {
            this.Hide();
            var screenLogin = new ScreenLogin();

            screenLogin.Show();
        }
コード例 #2
0
        /*
         * Button btnEnviar action
         */
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            if ((tbEmail.Text == "") ||
                (tbContato.Text == "") ||
                (tbCodigoCliente.Text == "") ||
                (tbAssunto.Text == "") ||
                (tbMensagem.Text == ""))
            {
                MessageBox.Show("Todos os campos são obrigatórios, preencha e tente novamente", "Campo(s) Vazio(s)", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (tbMensagem.Text == "")
                {
                    tbMensagem.Focus();
                }
                if (tbAssunto.Text == "")
                {
                    tbAssunto.Focus();
                }
                if (tbCodigoCliente.Text == "")
                {
                    tbCodigoCliente.Focus();
                }
                if (tbContato.Text == "")
                {
                    tbContato.Focus();
                }
                if (tbEmail.Text == "")
                {
                    tbEmail.Focus();
                }
            }
            else
            {
                try
                {
                    MailMessage mail       = new MailMessage();
                    SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                    mail.From = new MailAddress("*****@*****.**");
                    mail.To.Add("*****@*****.**");
                    mail.Subject = tbAssunto.Text;
                    mail.Body    = "Sent from:    " + tbEmail.Text + Environment.NewLine
                                   + "Client name:  " + Properties.Settings.Default.nomeUsuario + Environment.NewLine
                                   + "Phone number: " + tbContato.Text + Environment.NewLine
                                   + "Message: " + Environment.NewLine
                                   + tbMensagem.Text;

                    SmtpServer.Port        = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "atendimento1234");
                    SmtpServer.EnableSsl   = true;

                    SmtpServer.Send(mail);
                    MessageBox.Show("Obrigado pelo contato, reponderemos o mais rápido possível.", "Email Enviado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    tbAssunto.Text       = "";
                    tbMensagem.Text      = "";
                    tbEmail.Text         = "";
                    tbCodigoCliente.Text = "";
                    this.Hide();
                    var screenLogin = new ScreenLogin();
                    screenLogin.Show();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }