System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from, "One Ghost", System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "This is Email Body Text";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
//Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(from, "password");
client.Port =587; // 465; // 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.UseDefaultCredentials = false;
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
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 74.125.127.109:587
Just check out for the IP address and relative port number. It clearly says that this couldnot be done as the firewall on the server might not be allowing you to send any email. Also keep this in mind if you are sending any attachments with the email it
also creates the problem after some time.
If my ANSWER helps you in solving your problem MARK IT AS ANSWER
from the computer that is running your code, ping the ip address inb the error message (it may not always be
74.125.127.109 because Google likely uses many different servers for
gmail).
nslookup the ip address. with ping
and nslookup, you are checking for connectivity
C:\ ... >ping 74.125.127.109
Pinging 74.125.127.109 with 32 bytes of data:
Reply from 74.125.127.109: bytes=32 time=82ms TTL=50
Reply from 74.125.127.109: bytes=32 time=84ms TTL=50
Reply from 74.125.127.109: bytes=32 time=85ms TTL=50
Reply from 74.125.127.109: bytes=32 time=82ms TTL=50
Ping statistics for 74.125.127.109:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 82ms, Maximum = 85ms, Average = 83ms
C:\ ... >nslookup 74.125.127.109
Name: pz-in-f109.1e100.net
Address: 74.125.127.109
if ping can not reach your gmail ip address in a timely fashion, you will never connect; if nslookup fails to resolve smtp.gmail.com, or takes too long to reslove smtp.gmail.com, you can also experience a timeout.
IP Address: 74.125.127.109
Location UNITED STATES, -, -
Latitude, Longitude 38.9048, -77.0354 (38°54'17"S -77°2'7"E)
Connection through GOOGLE INC
Local Time 01 Mar, 2012 03:28 PM (UTC -05:00)
Domain GOOGLE.COM
Net Speed DSL
set a breakpoint on client.Send(mail); and run your code in
debug mode; inspect all of your settings to ensure that they are correct
search videos at Google with debug visual studio 2010
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
kapiltapa
Member
42 Points
148 Posts
I am unable to send mail
Mar 01, 2012 01:10 AM|LINK
I am using the code like this
string from = "vvpnkapil@gmail.com";
string to = "debugger.kapil@yahoo.com";
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from, "One Ghost", System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "This is Email Body Text";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
//Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(from, "password");
client.Port =587; // 465; // 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.UseDefaultCredentials = false;
client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
client.Send(mail);
ClientScript.RegisterStartupScript(this.GetType(), "popup", "alert('Email Send Succesfully');", true);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
}
the above code is giving error
can any body suggest me the right one..
gerrylowry
All-Star
20525 Points
5713 Posts
Re: I am unable to send mail
Mar 01, 2012 02:17 AM|LINK
@ kapiltapa
??? what error is your code giving?
g,
kattyjems
Member
120 Points
50 Posts
Re: I am unable to send mail
Mar 01, 2012 04:52 AM|LINK
Hi,
Could you please provide the error that you are getting.?
kapiltapa
Member
42 Points
148 Posts
Re: I am unable to send mail
Mar 01, 2012 05:44 AM|LINK
Error message :
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 74.125.127.109:587
codeseed
Member
529 Points
146 Posts
Re: I am unable to send mail
Mar 01, 2012 08:37 AM|LINK
Hi Kapil,
Just check out for the IP address and relative port number. It clearly says that this couldnot be done as the firewall on the server might not be allowing you to send any email. Also keep this in mind if you are sending any attachments with the email it also creates the problem after some time.
gerrylowry
All-Star
20525 Points
5713 Posts
Re: I am unable to send mail
Mar 01, 2012 09:42 AM|LINK
@ kapiltapa
from the computer that is running your code, ping the ip address inb the error message (it may not always be 74.125.127.109 because Google likely uses many different servers for gmail).
nslookup the ip address. with ping and nslookup, you are checking for connectivity
C:\ ... >ping 74.125.127.109 Pinging 74.125.127.109 with 32 bytes of data: Reply from 74.125.127.109: bytes=32 time=82ms TTL=50 Reply from 74.125.127.109: bytes=32 time=84ms TTL=50 Reply from 74.125.127.109: bytes=32 time=85ms TTL=50 Reply from 74.125.127.109: bytes=32 time=82ms TTL=50 Ping statistics for 74.125.127.109: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 82ms, Maximum = 85ms, Average = 83ms C:\ ... >nslookup 74.125.127.109 Name: pz-in-f109.1e100.net Address: 74.125.127.109if ping can not reach your gmail ip address in a timely fashion, you will never connect; if nslookup fails to resolve smtp.gmail.com, or takes too long to reslove smtp.gmail.com, you can also experience a timeout.
C:\>nslookup smtp.gmail.com Non-authoritative answer: Name: gmail-smtp-msa.l.google.com Addresses: 209.85.225.108 209.85.225.109 Aliases: smtp.gmail.com C:\>http://www.ip2location.com/74.125.127.109
set a breakpoint on client.Send(mail); and run your code in debug mode; inspect all of your settings to ensure that they are correct
compare your code to my example code here: http://forums.asp.net/post/4815647.aspx.
g.
* walking your code with your debugger:
video, c. 8 minutes: http://msdn.microsoft.com/en-ca/vstudio/ee672313.aspx
"How Do I: Step with The Debugger in Visual Studio?"
Debugging: http://lmgtfy.com/?q=debug+visual+studio+2010
example: http://www.codeproject.com/KB/cs/MasteringInDebugging.aspx
videos: http://www.youtube.com/watch?v=z5gBIizwsY0
search videos at Google with debug visual studio 2010
kctt
Contributor
5004 Points
948 Posts
Re: I am unable to send mail
Mar 05, 2012 01:49 AM|LINK
It could be firewall blocks port 587.
From your server check telnet smtp.gmail.com on port 587