2
The SMTP server requires a secure connection or the client has not been authenticated?
[HttpPost]
public ActionResult Index(string login)
{
try
{
var tbuscar = new UsuarioAplicacao();
var retorno = tbuscar.ListarPorLogin(login);
if (retorno != null)
{
string infLogin = retorno.login;
string infSenha = retorno.senha;
string infNome = retorno.nomeusuario;
int infId = retorno.idusuario;
string texto = "O seu login é : " + infLogin + " é sua senha é : " + infSenha;
SmtpClient smtp = new SmtpClient("smtp.mail.yahoo.com", 587);
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "senha");
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage m = new MailMessage();
m.Subject = "Recuperação de senha";
m.Body = "Segue informações sobre usuário e senha: \n" + texto;
m.To.Add(infLogin);
m.From = new MailAddress("[email protected]");
m.IsBodyHtml = true;
smtp.Send(m);
TempData["msg"] = "E-mail enviado com sucesso";
}
else
{
TempData["Erro"] = "Usuário não cadastrado.";
}
ModelState.Clear();
}
catch (Exception ex)
{
TempData["Erro"] = ex.Message;
}
return View();
}
Maybe you are using the real Gmail password, Google does not allow this type of operation. Here’s how to create a password for less secure apps: https://support.google.com/accounts/answer/6010255
– rubStackOverflow
This code of yours would work with yahoo, I have an application running that almost equal to your code. If google is not a must for you try with yahoo.
– Ricardo
@Ricardo, I’ll do a test using yahoo
– Harry
What is the error? Here in the codeproject you have a good example: http://www.codeproject.com/Tips/520998/Send-Email-from-Yahoo-GMail-Hotmail-Csharp
– Marconi