Viene visualizzato un messaggio di errore quando si tenta di inviare un'e-mail tramite il mio servizio web. Ho provato ad abilitare l'accesso ad app meno sicure disabilitando la verifica in due passaggi e accedendo all'account tramite un browser web. Nessuna delle soluzioni su SO ha funzionato per me. Sto ancora ottenendo:Come inviare un'e-mail con C# tramite Gmail
Error: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Cosa posso fare per risolvere questo problema?
namespace EmailService
{
public class Service1 : IService1
{
public string SendEmail(string inputEmail, string subject, string body)
{
string returnString = "";
try
{
MailMessage email = new MailMessage();
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
// set up the Gmail server
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "mypassword");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
// draft the email
MailAddress fromAddress = new MailAddress("[email protected]");
email.From = fromAddress;
email.To.Add(inputEmail);
email.Subject = body;
email.Body = body;
smtp.Send(email);
returnString = "Success! Please check your e-mail.";
}
catch(Exception ex)
{
returnString = "Error: " + ex.ToString();
}
return returnString;
}
}
}
Vedere se questo aiuta: http://stackoverflow.com/questions/18503333/the-smtp-server-requires-a-secure-connection-o r-the-client-was-not-authenticated –
Hai provato a eseguire il ping del server, in caso affermativo la soluzione menzionata da Eghbal Sohrabi è ok – Shubhojit
@Shubhojit esegue il ping del server di Google? – Johnny