Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

.NET C# Send email error, C# Send email error

views
     
TSStraike
post Feb 16 2017, 05:31 PM, updated 8y ago

Getting Started
**
Junior Member
97 posts

Joined: Dec 2010
Hi, I have encountered this error in my code and I dont know how to fix it. Anybody can guide me?
Attached Image

Code:

MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient("smtp.google.com", 25);

mail.From = new MailAddress("abc@gmail.com");
mail.To.Add("abc@hotmail.com");
mail.Subject = "Testing";
mail.Body = "Testing 123";

client.Credentials = new System.Net.NetworkCredential("from mail", "password");
client.UseDefaultCredentials = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;

client.Send(mail);

This post has been edited by Straike: Feb 16 2017, 05:40 PM
dewill
post Feb 16 2017, 06:10 PM

Regular
******
Senior Member
1,716 posts

Joined: Feb 2006


QUOTE(Straike @ Feb 16 2017, 05:31 PM)
Hi, I have encountered this error in my code and I dont know how to fix it. Anybody can guide me?
Attached Image

Code:

MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient("smtp.google.com", 25);

mail.From = new MailAddress("abc@gmail.com");
mail.To.Add("abc@hotmail.com");
mail.Subject = "Testing";
mail.Body = "Testing 123";

client.Credentials = new System.Net.NetworkCredential("from mail", "password");
client.UseDefaultCredentials = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;

client.Send(mail);
*
Kindly go check Gmail configuration. Your port is definitely not 25

TSStraike
post Feb 16 2017, 06:29 PM

Getting Started
**
Junior Member
97 posts

Joined: Dec 2010
This is the error message:
ErrorSystem.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 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 43.252.213.77:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at WebApplication2.HomePage.sendMail_Click(Object sender, EventArgs e) in c:\Users\User\Documents\Visual Studio 2013\Projects\WebApplication1\WebApplication2\HomePage.aspx.cs:line 52
TSStraike
post Feb 16 2017, 06:29 PM

Getting Started
**
Junior Member
97 posts

Joined: Dec 2010
QUOTE(dewill @ Feb 16 2017, 06:10 PM)
Kindly go check Gmail configuration. Your port is definitely not 25
*
But I only follow the tutorial in YouTube. The exact same code..
alien3d
post Feb 16 2017, 06:30 PM

Look at all my stars!!
*******
Senior Member
3,740 posts

Joined: Mar 2009
QUOTE(Straike @ Feb 16 2017, 06:29 PM)
But I only follow the tutorial in YouTube. The exact same code..
*
try 587 port instead
TSStraike
post Feb 16 2017, 06:36 PM

Getting Started
**
Junior Member
97 posts

Joined: Dec 2010
QUOTE(alien3d @ Feb 16 2017, 06:30 PM)
try 587 port instead?
*
It works miraculously! Thank you so much!! But why 587 and not 25?
dewill
post Feb 17 2017, 04:31 PM

Regular
******
Senior Member
1,716 posts

Joined: Feb 2006


QUOTE(Straike @ Feb 16 2017, 06:36 PM)
It works miraculously! Thank you so much!! But why 587 and not 25?
*
Kindly go check Gmail configuration. Your port is definitely not 25

wonder how you deploy something without understanding certain configuration and blindly taken from youtube
alien3d
post Feb 17 2017, 04:53 PM

Look at all my stars!!
*******
Senior Member
3,740 posts

Joined: Mar 2009
QUOTE(Straike @ Feb 16 2017, 06:36 PM)
It works miraculously! Thank you so much!! But why 587 and not 25?
*
in old days port 25 have been used by spammer.. then everybody changed to 587

Read here

https://support.google.com/mail/answer/7126229?hl=en

QUOTE
Outgoing Mail (SMTP) Server
smtp.gmail.com

Requires SSL: Yes

Requires TLS: Yes (if available)

Requires Authentication: Yes

Port for SSL: 465

Port for TLS/STARTTLS: 587


 

Change to:
| Lo-Fi Version
0.0121sec    0.28    6 queries    GZIP Disabled
Time is now: 29th March 2024 - 12:58 AM