Click here to Skip to main content
12,955,891 members (65,625 online)
Rate this:
 
Please Sign up or sign in to vote.
Hi All
I’m trying to send an email in asp.net but I receive the following error  :
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtp.google.com' at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, 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 MS_ContactUS.btnSend_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\MediaSign\MS-ContactUS.aspx.cs:line 48


This is the code-behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Configuration;
 
public void btnSend_Click(object sender, EventArgs e)
    {
        MailMessage mm = new MailMessage("sender@gmail.com", "receiver@gmail.com");
        mm.Subject = txtSubject.Text;
        mm.Body = "<br /><br />Email: " + txtFrom.Text + "<br />" + txtBody.Text;
 
        mm.IsBodyHtml = false;
 
        SmtpClient smtp = new SmtpClient();
 
        smtp.Host = "smtp.google.com";
 
        System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
 
        NetworkCred.UserName = "sender@gmail.com";
 
        NetworkCred.Password = "xxxxx";
 
        smtp.UseDefaultCredentials = true;
 
        smtp.Credentials = NetworkCred;
 
        smtp.EnableSsl = true;
 
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
 
        smtp.Port = 578;
        try
        {
            smtp.Send(mm);
        }
        catch(Exception ex)
        {
            Label1.Text = ex.ToString();
        }
}

This is web.config :

smtp from="sender@gmail.com"
network host="smtp.google.com" defaultcredentials="true" port="578" username="sender@gmail.com" password="xxxxx"
smtp

Note: i have intentionally removed starting and ending tags for the web.congig in here for proper view.

This is the aspx page :
<div>
         
        Message from: <asp:TextBox ID="txtFrom" runat="server" /><br />
        Subject: <asp:TextBox ID="txtSubject" runat="server" /><br />
        Message Body:<br />
        <asp:TextBox ID="txtBody" runat="server" Height="171px" TextMode="MultiLine" Width="270px" /><br />
        <asp:Button CssClass="CTD-button" runat="server" ID="btnSend" Text="send" OnClick="btnSend_Click" /> 
        <asp:Label ID="Label1" runat="server" Text="Label"><br /><br />
           
    </div>
Posted 28-Jul-12 20:59pm
X Guy219
Updated 29-Jul-12 1:01am
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If it can't find the google mail server, it's either down ( not likely ) or you're not connected to the internet, or it's being blocked.
  Permalink  
Comments
X Guy 29-Jul-12 3:15am
   
well i'm connected to the internet, u mean my firewall is blocking my visual studio accessibility??? (i have opened visual studio as administrator in win7)
i also disabled my anti-virus and firewall, still getting the same error :(
aspnet_regiis 29-Jul-12 4:54am
   
If the traffic is blocked in network, any of these actions will not have any effect.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

The error message -

System.Net.Mail.SmtpException: The operation has timed out. at System.Net.Mail.SmtpClient.Send(MailMessage message) at MS_ContactUS.btnSend_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\MediaSign\MS-ContactUS.aspx.cs:line 48


clearly means that you are not able to connect to the SMTP server.

The reasons behind this can be:

1. Firewall has blocked access to it in your system.

2. If you are in a corporate network, then your network administrator has blocked access to gmail.
Check with your network administrator.
  Permalink  
Comments
X Guy 29-Jul-12 5:32am
   
about ur 1st suggestion i completely disabled my anti-virus and firewall and also windows defender.
and about the 2end one i also tried it at home but the same results r returned :(
aspnet_regiis 29-Jul-12 6:46am
   
Unless you get the ping reply similar to this , your problem will not be resolved..
"C:\>ping smtp.gmail.com -t

Pinging gmail-smtp-msa.l.google.com [173.194.79.108] with 32 bytes of data:
Reply from 173.194.79.108: bytes=32 time=272ms TTL=43
Reply from 173.194.79.108: bytes=32 time=279ms TTL=43
Reply from 173.194.79.108: bytes=32 time=277ms TTL=43
Reply from 173.194.79.108: bytes=32 time=277ms TTL=43
Reply from 173.194.79.108: bytes=32 time=275ms TTL=43
Reply from 173.194.79.108: bytes=32 time=294ms TTL=43
Reply from 173.194.79.108: bytes=32 time=273ms TTL=43
Reply from 173.194.79.108: bytes=32 time=275ms TTL=43"
Since it is related to your network I can't guess what might be wrong with it.
X Guy 29-Jul-12 14:44pm
   
i have the same replies from the smtp server, that's why i can't figure it out.
aspnet_regiis 29-Jul-12 14:53pm
   
I searched a little on google and found people using port 587..But in your code it is " smtp.Port = 578;" ..Can test it once with 587 ?
X Guy 30-Jul-12 0:49am
   
i've checked 587,465 and 25 port numbers but no success .
this is my ping request :


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\>ping smtp.gmail.com -t

Pinging gmail-smtp-msa.l.google.com [173.194.67.109] with 32 bytes of data:
Reply from 173.194.67.109: bytes=32 time=248ms TTL=43
Reply from 173.194.67.109: bytes=32 time=246ms TTL=43
Reply from 173.194.67.109: bytes=32 time=245ms TTL=43
Reply from 173.194.67.109: bytes=32 time=247ms TTL=43
Reply from 173.194.67.109: bytes=32 time=246ms TTL=43
Reply from 173.194.67.109: bytes=32 time=247ms TTL=43
Reply from 173.194.67.109: bytes=32 time=246ms TTL=43
Reply from 173.194.67.109: bytes=32 time=245ms TTL=43
Reply from 173.194.67.109: bytes=32 time=247ms TTL=43
Reply from 173.194.67.109: bytes=32 time=246ms TTL=43
Reply from 173.194.67.109: bytes=32 time=246ms TTL=43
Reply from 173.194.67.109: bytes=32 time=250ms TTL=43
Reply from 173.194.67.109: bytes=32 time=252ms TTL=43
Reply from 173.194.67.109: bytes=32 time=244ms TTL=43
Reply from 173.194.67.109: bytes=32 time=253ms TTL=43
Reply from 173.194.67.109: bytes=32 time=245ms TTL=43

Ping statistics for 173.194.67.109:
Packets: Sent = 16, Received = 16, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 244ms, Maximum = 253ms, Average = 247ms
Control-C
^C
C:\>
X Guy 30-Jul-12 0:53am
   
guys does it have any thing to do with IIS??
i've also set smtp E-mail Configuration in that.
Note : i'm using IIS 7.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

See my answer given for similar question asked earlier: The remote name could not be resolved [^]

Do have a look at the working implementation here:
Send Mail / Contact Form using ASP.NET and C#[^]
sending email in asp.net using smtp gmail server[^]
  Permalink  
Comments
X Guy 29-Jul-12 3:33am
   
when i ping smtp.google.com it says :
ping request could not find host smpt.google.com , plz check the name and try again!!! :(
X Guy 29-Jul-12 4:11am
   
i changed the smtp server to smtp.gmail.com
now i get the following error :

System.Net.Mail.SmtpException: The operation has timed out. at System.Net.Mail.SmtpClient.Send(MailMessage message) at MS_ContactUS.btnSend_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\MediaSign\MS-ContactUS.aspx.cs:line 48

i have some reply from smtp.gmail.com in ping request.
Sandeep Mewara 29-Jul-12 15:30pm
   
It should be:
smtp.gmail.com with port 587

Did you even go through my links in answer?
X Guy 30-Jul-12 0:44am
   
yeah at first the port number was wrong and i changed it to 587,but to ur surprise it's returning the same result "System.Net.Mail.SmtpException: The operation has timed out. at System.Net.Mail.SmtpClient.Send(MailMessage message) at MS_ContactUS.btnSend_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\MediaSign\MS-ContactUS.aspx.cs:line 48
" i've even tried 465 and 25 port numbers but no success :(

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,719
CHill60 3,550
Maciej Los 3,153
ppolymorphe 2,060
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 29 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100