Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi dear all
This my code that i wrote it

C#
MailMessage msg = new MailMessage();

msg.From = new MailAddress("noreply@educclip.com", "My site                Registratration");
msg.To.Add(new MailAddress(email, name, System.Text.Encoding.UTF8));
msg.Subject = "Educclip - Register Account";
msg.IsBodyHtml = true;
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.None;
msg.Priority = MailPriority.Normal;

StreamReader sr = new StreamReader(Server.MapPath("~/ActiveMail.htm"));
string temp = sr.ReadToEnd();
temp = temp.Replace("[###Name###]", name).Replace("[###Url###]", key);
msg.Body = temp;

SmtpClient smtp = new SmtpClient("mail.educclip.com");
System.Net.NetworkCredential perm = new System.Net.NetworkCredential("noreply@educclip.com", "My host email's password");
smtp.Credentials = perm;
smtp.Send(msg);


it seems that it must work
but at the smtp.Send(msg) part i receive the error that email failed to send.
Is there any one to help me?
Thanks alot

Stack Trace:
------------
[SocketException (0x274c): 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 110.4.46.160:25]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +225
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +279

[WebException: Unable to connect to the remote server]
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +6054548
System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +314
System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21
System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +322
System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +146
System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +170
System.Net.Mail.SmtpClient.GetConnection() +50
System.Net.Mail.SmtpClient.Send(MailMessage message) +1484

[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +1811
NewUser.SendEmail(String email, String name, String key) in g:\Programming\Projects\Educclip2\Educclip Website(Mysql)\NewUser.aspx.cs:99
NewUser.SignupBtn_Click(Object sender, EventArgs e) in g:\Programming\Projects\Educclip2\Educclip Website(Mysql)\NewUser.aspx.cs:69
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Posted
Updated 15-Aug-12 3:26am
v2
Comments
Bernhard Hiller 15-Aug-12 4:57am    
"i receive the error that email failed to send.": some more details, please! Improve your question by copying the error message.
asasi_kamal 15-Aug-12 9:30am    
Dear Bernhard
As u told me i updated my question. Tq in advance.

Check the port for your mail server and also if SSL is required :
C#
smtp.Port = 25;
smtp.EnableSsl = True;
 
Share this answer
 
Comments
asasi_kamal 15-Aug-12 9:27am    
Dear Mehdi
It doesn't work. Do u have other idea?
Mehdi Gholam 15-Aug-12 9:35am    
ping mail.educclip.com and see if it is there.
asasi_kamal 15-Aug-12 9:40am    
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

D:\Users\Kamal>ping mail.educclip.com

Pinging mail.educclip.com [110.4.46.160] with 32 bytes of data:
Reply from 110.4.46.160: bytes=32 time=13ms TTL=116
Reply from 110.4.46.160: bytes=32 time=13ms TTL=116
Reply from 110.4.46.160: bytes=32 time=13ms TTL=116
Reply from 110.4.46.160: bytes=32 time=13ms TTL=116

Ping statistics for 110.4.46.160:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 13ms, Maximum = 13ms, Average = 13ms

D:\Users\Kamal>

asasi_kamal 15-Aug-12 9:40am    
it seems work?!
Mehdi Gholam 15-Aug-12 9:52am    
Contact your email provider for their smtp port number and configuration, also check your firewall allows your application network access.
TQ very much dear all. My problem was related to my stmp port. when i changed it to smtp.Port = 587; it started working correctly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900