Witam
W C# testuję możliwość wysłania maila z mojego adresu gmail (na razie)
na moją skrzynkę o takim samym adresie. Po uruchomieniu programu otrzymuję taki komunikat:
Unhandled exception. System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. For more information, go to
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
Proszę o pomoc, jak mam zmodyfikować kod poniższego programu:
using System.Net;
using System.Net.Mail;
using System.Text;
Console.WriteLine("Próba wysyłania maila.");
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("mój_email@gmail.com", "moje_haslo");
// tworzenie wiadomości
MailMessage mail = new MailMessage();
mail.From = new MailAddress("mój_email@gmail.com", "Moje nazwisko");
mail.To.Add("mój_email@gmail.com"); //odbiorca
mail.Subject = "Powitanie";
mail.Body = "Witaj!\n ";
mail.IsBodyHtml = true;
mail.BodyEncoding = Encoding.UTF8;
mail.SubjectEncoding = Encoding.UTF8;
//wysyłanie wiadomości
client.Send(mail);
W C# testuję możliwość wysłania maila z mojego adresu gmail (na razie)
na moją skrzynkę o takim samym adresie. Po uruchomieniu programu otrzymuję taki komunikat:
Unhandled exception. System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. For more information, go to
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
Proszę o pomoc, jak mam zmodyfikować kod poniższego programu:
using System.Net;
using System.Net.Mail;
using System.Text;
Console.WriteLine("Próba wysyłania maila.");
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("mój_email@gmail.com", "moje_haslo");
// tworzenie wiadomości
MailMessage mail = new MailMessage();
mail.From = new MailAddress("mój_email@gmail.com", "Moje nazwisko");
mail.To.Add("mój_email@gmail.com"); //odbiorca
mail.Subject = "Powitanie";
mail.Body = "Witaj!\n ";
mail.IsBodyHtml = true;
mail.BodyEncoding = Encoding.UTF8;
mail.SubjectEncoding = Encoding.UTF8;
//wysyłanie wiadomości
client.Send(mail);