-1
When creating my program, I put a Form so that you can "Report Error/Suggestions". In this way I put 2 textbox and 1 button. 1 textbox for Subject, and the other so that you can write what you want (message).
The button
serves to send this data to my email. The code I have is as follows::
if (!(txtpara.Text.Trim() == ""))
{
To = txtpara.Text;
Subject = txtassunto.Text;
Body = txtmensagem.Text;
mail = new MailMessage();
mail.To.Add(new MailAddress(this.To));
mail.From = new MailAddress("[email protected]");
mail.Subject = Subject;
mail.Body = Body;
mail.IsBodyHtml = false;
SmtpClient client = new SmtpClient("smtp.gmail.com", 465);
using (client)
{
client.Credentials = new System.Net.NetworkCredential("[email protected]", "aminhapassword");
client.EnableSsl = true;
client.Send(mail);
}
MessageBox.Show("E-Mail enviado com Sucesso!", "Sucesso");
}
The mistake is in:
"client. Send(mail);", and says: "Failed to send email" - Smtpexception.
Welcome to the en OS. Please read How to ask a good question?. You have not reported what you have done so far, what are your specific doubts or problems you are having.
– Molx
Edited friend @Molx.
– Don Vito
@Godfathersantanta, you described the problem better, but I will insist a little. You need to be clearer. If you have no idea where to start, maybe the ideal is to look for tutorials like How to send email with C code#?. In the OR, we seek to answer more specific questions. For example, if you’re a code ready but it doesn’t work, you could post the important part for someone to take a look at.
– Molx
Dear @Molx, that’s what I’ve done, but at the time of "client.Send(message)", it always gives me error. I’ve tried several methods without success...
– Don Vito
Could you put more information on your smtp server? Sometimes the problem is just that it is not connected or something like that... Still, if you can detail better the SMTP exception that he is releasing, it already helps as well.
– Felipe Avelar
Hi @Felipeavelar, how so more information about my smtp server? I have to do something in my gmail account?
– Don Vito