Outline ·
[ Standard ] ·
Linear+
.NET C# Send email error, C# Send email error
TSStraike
|
Feb 16 2017, 05:31 PM, updated 8y ago
|
Getting Started
|
Hi, I have encountered this error in my code and I dont know how to fix it. Anybody can guide me?
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
|
Feb 16 2017, 06:10 PM
|
|
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?
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
|
Feb 16 2017, 06:29 PM
|
Getting Started
|
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
|
Feb 16 2017, 06:29 PM
|
Getting Started
|
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
|
Feb 16 2017, 06:30 PM
|
|
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
|
Feb 16 2017, 06:36 PM
|
Getting Started
|
QUOTE(alien3d @ Feb 16 2017, 06:30 PM) It works miraculously! Thank you so much!! But why 587 and not 25?
|
|
|
|
dewill
|
Feb 17 2017, 04:31 PM
|
|
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
|
Feb 17 2017, 04:53 PM
|
|
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=enQUOTE 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
|
|
|
|