0
protected void btnEnviar_Click(object sender, EventArgs e)
{
string desEmail = "[email protected]";
string remetenteEmail = txtEmail.Text; //O e-mail do remetente
MailMessage mail = new MailMessage();
mail.To.Add(desEmail);
mail.From = new MailAddress(remetenteEmail, txtNome.Text, System.Text.Encoding.UTF8);
mail.Subject = txtAssunto.Text;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = txtMensagem.Text;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High; //Prioridade do E-Mail
SmtpClient client = new SmtpClient(); //Adicionando as credenciais do seu e-mail e senha:
client.Credentials = new System.Net.NetworkCredential(desEmail, "123456");
client.Port = 587; // Esta porta é a utilizada pelo Gmail para envio
client.Host = "smtp.gmail.com"; //Definindo o provedor que irá disparar o e-mail
client.EnableSsl = true; //Gmail trabalha com Server Secured Layer
try
{
client.Send(mail);
lblMensagem.Text = "Envio do E-mail com sucesso";
lblMensagem.Visible = true;
}
catch (Exception ex)
{
lblMensagem.Text = "Ocorreu um erro ao enviar:" + ex.Message;
lblMensagem.Visible = true;
}
}
}
I think you are just getting confused in matter of Sender (Who is sent the email) and Recipient(Who will receive the email) in your code, so much so that in SMTP you use the Recipient.. However the SMTP has to be from the Sender (Who sends the email, in case it would be your e-mail server) and the Recipient is who will receive, This is variable that is informed in the txtEmail.Text field;
– Edenilson Bila
Your error ai is basically in this line: client. Credentials = new System.Net.Networkcredential(desEmail, "123456");
– Edenilson Bila