简体   繁体   中英

SMTP email using gmail sockets

I try to make an email service in my project using Gmail SMTP , but when the Socket connection start I get this error:

"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 64.233.166.109:25"

This is a part of the code:

private static string SmtpServer = "smtp.gmail.com";

private enum SMTPResponse : int
{
    CONNECT_SUCCESS = 220,  
    GENERIC_SUCCESS = 250,
    DATA_SUCCESS = 354,
    QUIT_SUCCESS = 221
}

public static bool Send(MailMessage message)
{
    IPHostEntry IPhst = Dns.GetHostEntry(SmtpServer);
    IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
    Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
    s.Connect(endPt);
}

Try port 587 instead of port 25.

Port 25 is for smtp server to smtp server smtp communication.
Port 587 is for client to server smtp communication.

Outgoing connections to port 25 are frequently blocked to stop outgoing spam.
Connections to port 587 require some kind of authentication.

https://en.wikipedia.org/wiki/Mail_submission_agent

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM