Otrzymuję komunikat o błędzie podczas próby wysłania wiadomości e-mail za pośrednictwem mojego serwisu internetowego. Próbowałem umożliwić dostęp do mniej bezpiecznych aplikacji, wyłączając weryfikację 2-etapową i logując się na konto za pomocą przeglądarki internetowej. Żadne z rozwiązań SO nie sprawdziło się u mnie. Wciąż otrzymuję:Jak wysłać wiadomość e-mail z C# przez Gmaila
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.
Co mogę zrobić, aby rozwiązać ten problem?
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;
}
}
}
Zobacz, czy to pomaga: http://stackoverflow.com/questions/18503333/the-smtp-server-requires-a-secure-connection-o r-the-client-was-not-authenticated –
Czy próbowałeś pingować serwer, jeśli tak, to rozwiązanie wspomniane przez Eghbala Sohrabiego jest ok. – Shubhojit
@Shubhojit pingować serwer Google? – Johnny