Possible Duplicate:
GMail SMTP via C# .Net errors on all portsWysyłanie wiadomości e-mail za pośrednictwem GMail w .NET
otrzymuję następujący błąd, gdy próbuję wysłać wiadomość e-mail w moim C# programu. Używam programu Visual Studio 2008 na Windows 7. Chciałbym wkleić mój kod, a następnie błąd:
class email_log_files
{
private string login_username = "my_gmail_id";
private string login_password = "my_gmail_password";
public void send_email()
{
string src_address = "[email protected]";
string dest_address = "[email protected]";
try
{
MailMessage email_msg = new MailMessage();
SmtpClient email_client = new SmtpClient();
email_msg.From = new MailAddress(src_address);
email_msg.Sender = new MailAddress(src_address);
email_msg.ReplyTo = new MailAddress(src_address);
email_msg.To.Add(dest_address);
email_msg.Subject = "Test";
email_msg.Body = "Body of the message";
NetworkCredential credentials = new NetworkCredential(login_username, login_password);
email_client.Credentials = credentials;
email_client.Host = "smtp.gmail.com";
email_client.Port = 465;
email_client.EnableSsl = true;
email_client.Send(email_msg);
Console.WriteLine("Message Sent Successfully!!");
Console.ReadLine();
}
}
}
a komunikat o błędzie jest następujący:
The operation has timed out.
Dlaczego zawsze limit czasu? Jestem pewien, że mam poprawny adres serwera SMTP i numer portu dla Gmaila, ponieważ mam skonfigurowany mój Outlook z tym samym. Jakaś pomoc lub pomysły?
Po zmianie portu na 587 błąd wygląda następująco. Właśnie wyłączyłem zaporę sieciową, aby sprawdzić, czy to nie był problem. Nowy błąd (na porcie 587):
Ów problem dla mnie, kiedy zmienić port 587:
Failure sending mail.
System.Net.WebException: Unable to connect to the remote server ---> System.Net.
Sockets.SocketException: No connection could be made because the target machine
actively refused it 74.125.113.109:587
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre
ss socketAddress)
at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Sock
et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state,
IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object ow
ner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket
6, Int32 timeout)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32
timeout, GeneralAsyncDelegate asyncCallback)
at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate
asyncCallback)
at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncD
elegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
System
System.Collections.ListDictionaryInternal
Dzięki, VP
Nie ma czegoś takiego jak C# .NET. C# to język programowania, .NET jest platformą. –
Dziękuję. Czy miałeś czas na skupienie się na moim prawdziwym pytaniu tutaj? – zack
Myślę, że Scott ma rację, gmail wydaje się odpowiadać na porty 25 i 587. –