C
C#•2y ago
yumo

Error with app send email

The goal is to make a send emails app from c# , later on to also send with attachments but im stuck at this for the past 2 hours As you can see in the image its saying the error is on line 52 Here is what i have done till now: line 52 is the line smpt.Send(msg);
private void btnEnviar_Click(object sender, EventArgs e)
{
try
{
//Criar duas string s que contenham o email e a password

string from = "myemailinfo";
string password = "mypasswordhere";

//Criar o objeto de acesso ah class mail
MailMessage msg = new MailMessage();
msg.Subject = txtAssunto.Text;
msg.From = new MailAddress(from);
msg.Body = txtMensagem.Text;
msg.To.Add(new MailAddress(cmbEmail.Text));

SmtpClient smpt = new SmtpClient();

smpt.Host = "smpt.gmail.com";

smpt.Port = 587;

smpt.UseDefaultCredentials = false;

smpt.EnableSsl = true;

NetworkCredential nc = new NetworkCredential(from, password);

smpt.Credentials = nc;

smpt.Send(msg);

MessageBox.Show("Email Enviado com sucesso!");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnEnviar_Click(object sender, EventArgs e)
{
try
{
//Criar duas string s que contenham o email e a password

string from = "myemailinfo";
string password = "mypasswordhere";

//Criar o objeto de acesso ah class mail
MailMessage msg = new MailMessage();
msg.Subject = txtAssunto.Text;
msg.From = new MailAddress(from);
msg.Body = txtMensagem.Text;
msg.To.Add(new MailAddress(cmbEmail.Text));

SmtpClient smpt = new SmtpClient();

smpt.Host = "smpt.gmail.com";

smpt.Port = 587;

smpt.UseDefaultCredentials = false;

smpt.EnableSsl = true;

NetworkCredential nc = new NetworkCredential(from, password);

smpt.Credentials = nc;

smpt.Send(msg);

MessageBox.Show("Email Enviado com sucesso!");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Can someone help me why is it saying this?
18 Replies
Sossenbinder
Sossenbinder•2y ago
Are you sure smpt.gmail is right? Shouldn't it be smtp? Yeah it should DNS Resolution is your issue since smpt.gmail.com is not a thing nslookup is your friend 😄
yumo
yumoOP•2y ago
yeah it was wrong but it was a variable so that wouldnt solve the problem i changed all the smpt to smtp and is saying the same still
Sossenbinder
Sossenbinder•2y ago
Did you correct this line? smpt.Host = "smpt.gmail.com";
yumo
yumoOP•2y ago
its saying that the server SMTP needs one safe connection or the client its not authenticated
yumo
yumoOP•2y ago
after i corrected that its showing me the error above
Sossenbinder
Sossenbinder•2y ago
Okay, now you're running into an authentication issue So the domain is now properly resolved You might want to look up whether your authentication procedure is correctly implemented But it's one step forward from the last issue
yumo
yumoOP•2y ago
i have the correct data, is it possible to be because im sendind an email to myself? how can i make it to send to hotmail to
Sossenbinder
Sossenbinder•2y ago
It's been a while since I worked with it, but I think if you are working with username & password instead of oauth for authentication, you need to enable "Less secure apps" in your gmail account That might be your issue https://myaccount.google.com/lesssecureapps
yumo
yumoOP•2y ago
didnt they remove that option some months ago? i will check
Sossenbinder
Sossenbinder•2y ago
Not sure, as I said, it's been a while since I used that
yumo
yumoOP•2y ago
yeah its not available again "This setting is no longer available."
Sossenbinder
Sossenbinder•2y ago
Hmm, I see
Sossenbinder
Sossenbinder•2y ago
WP Mail SMTP
Gmail Is Disabling Less Secure Apps: What To Do Next
Google is deprecating Less Secure Apps. Find out how to fix your Gmail connection in WP Mail SMTP.
Sossenbinder
Sossenbinder•2y ago
I found this I would assume if they turn it off they must have some kind of migration guide somewhere for people relying on that setting
yumo
yumoOP•2y ago
yeah but i didnt want to use wordpress to send emails im gonna try and look for App passwords on google settings
Sossenbinder
Sossenbinder•2y ago
Sounds good Feel free to let me know if that worked, I'd also be interested
yumo
yumoOP•2y ago
wow option 2 it worked!
Sossenbinder
Sossenbinder•2y ago
Good to know 👌
Want results from more Discord servers?
Add your server