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
Sossenbinder2y 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
yumo2y 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
Sossenbinder2y ago
Did you correct this line? smpt.Host = "smpt.gmail.com";
yumo
yumo2y ago
its saying that the server SMTP needs one safe connection or the client its not authenticated
yumo
yumo2y ago
after i corrected that its showing me the error above
Sossenbinder
Sossenbinder2y 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
yumo2y 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
Sossenbinder2y 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
yumo2y ago
didnt they remove that option some months ago? i will check
Sossenbinder
Sossenbinder2y ago
Not sure, as I said, it's been a while since I used that
yumo
yumo2y ago
yeah its not available again "This setting is no longer available."
Sossenbinder
Sossenbinder2y ago
Hmm, I see
Sossenbinder
Sossenbinder2y 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
Sossenbinder2y 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
yumo2y ago
yeah but i didnt want to use wordpress to send emails im gonna try and look for App passwords on google settings
Sossenbinder
Sossenbinder2y ago
Sounds good Feel free to let me know if that worked, I'd also be interested
yumo
yumo2y ago
wow option 2 it worked!
Sossenbinder
Sossenbinder2y ago
Good to know 👌
Want results from more Discord servers?
Add your server
More Posts
❔ Can someone help me with my snake game?Hi everyone reading this. I’m pretty new to C#, so please go easy on me. I have a snake-game (wpf)✅ ConsoleApp - run the .exe by cmd and catch given parametersWell, as a little task I'm trying to code a ConsoleApp that should base64 encrypt an input string ~~❔ Bad IL Format Exception when porting .NET Framework 4.8 Project to .NET Core 6.0Hi, I've currently got the glorious task to port a .NET Framework 4.8 project to .NET Core 6.0. So f❔ "Cannot assign requested address [::1]:27017" when connecting to MongoDB on Docker.I have a Docker Compose file with containers - `backend`: ASP.NET Core web API - `mongo`: MongoDB wh❔ External Login Callback (Facebook works, Google doesn't)This is copied from a youtube tutorial and I've been trying to step through and figure out the probl❔ Need someone who is an expert at rating resumes, would really appreciate itMy resume https://cdn.discordapp.com/attachments/684475244664193242/1065827594806763580/Yehor-Belenk❔ Handling different version changes for external standard.Hey! I'm developing tools for a community to support OpenDRIVE standard. The name of the standard do❔ IMAP vs POP3 for getting attachments from an emailI'm building a console app in C# using MailKit to find and save all of the attachments in my outlook❔ WPF MVVM ModelViews and ViewsI have recently learned that ModelView can't have UI elements in it (bad practice). Hence, couple of❔ RatelimitHello, i am currently trying to program a discord bot. Ive created a method to track how many player