Witam,
Ostatnio chciałem napisać funkcjonalność wysyłania emaili. Chciałem wykorzystać do tego serwer od gmaila (smtp.gmail.com) ale natrafiłem na błąd którego nie jestem w stanie od kilku dni rozwiązać.
Na porcie (z włączonym ssl):
- 25 - Mailbox unavailable. The server response was: No SMTP server defined. Use real server address instead of 127.0.0.1 in your account.
- 465 - Unable to read data from the transport connection: The connection was closed
- 587 - Server does not support secure connections
Na porcie (bez ssl):
- 25 - Mailbox unavailable. The server response was: No SMTP server defined. Use real server address instead of 127.0.0.1 in your account.
- 465 - Unable to read data from the transport connection: The connection was closed.
- 587 - Mailbox unavailable. The server response was: No SMTP server defined. Use real server address instead of 127.0.0.1 in your account.
Pracuję na Windows 10
Do Gmaila łączę się z sieci domowej, wyłączałem firewalla/win defendera, odczekiwałem jakiś czas i ponawiałem próbę (~dnia)
Jeśli nie da się rozwiązać problemu z tym serwerem (bo np. google coś pozmieniał i się nie da) to czy są jakieś alternatywy do smtp.gmail.com?
Może ktoś pomóc mi rozwiązać problem? Z góry dziękuję
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
namespace Gmail_new
{
class Program
{
static void Main(string[] args)
{
SendMail().Wait();
}
static async Task SendMail()
{
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 465;
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("[email protected]", "pass");
smtp.UseDefaultCredentials = false;
MailMessage mess = new MailMessage();
mess.From = new MailAddress("[email protected]");
mess.To.Add(new MailAddress("[email protected]"));
mess.Subject = "Any subject";
mess.Body = "My body";
mess.IsBodyHtml = true;
await smtp.SendMailAsync(mess);
}
}
}