Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi am getting this error "could not resolve remote "The remote name could not be resolved: 'smtp.gmail.com'" or this one "Failure sending mail.System
".i use internet on proxy sever. how to rectify the said error

C#
      MailMessage msg = new MailMessage();
       msg.From = new MailAddress("demoejk@gmail.com");
       msg.To.Add("demoejk@gmail.com");
       msg.Subject = "Sucessfull Regesiration to F2";
       msg.IsBodyHtml = true;
       msg.Body = "Congrats " + TextBox1.Text + "  u have been sucessfully registred to F2 Keep visiting regularly ";
       SmtpClient client = new SmtpClient("Smtp.gmail.com", 587);
       client.Credentials = new NetworkCredential("demrike", "XXXXXXXX");
       client.EnableSsl = true;
       try
       {
           client.Send(msg);
           Response.Write("mes has been sent");
       }
       catch (Exception er)
       {
           Response.Write(er.Message);
           Response.Write(er.Source.ToString());
>      }
Posted
Updated 23-Jan-12 18:40pm
v2

Are you able to ping smtp.gmail.com from your computer?
 
Share this answer
 
Comments
anoop_vip 23-Jan-12 2:33am    
yes i am able to ping it
There is nothing wrong with your code.
Since you are using ASP.NET, can you try adding the following in web.config file

C#
<system.net>
	<defaultproxy>
		<proxy proxyaddress="ip address of proxy server" />
	</defaultproxy>
</system.net>
 
Share this answer
 
Comments
Sriram Chitturi 24-Jan-12 5:58am    
Anoop, there is nothing wrong with your code. It worked as it is from my machine.
Did you get a chance to set the proxy address in web.config and try.
The error is self descriptive, system unable to access Smtp.gmail.com from your machine.
1. check firewall settings
2. try pinging Smtp.gmail.com from your machine
3. open a command prompt, and type "nslookup www.gmail.com". see if you get response and domain ip
if not then your domain setting
 
Share this answer
 
use this code

MailMessage oMsg = new MailMessage();
                oMsg.From = new MailAddress("xxx@gmail.com", "xxx");
                oMsg.To.Add(new MailAddress("yyy@gmail.com", "xxx"));
                oMsg.Subject = "Packet Parsing Problem";
                oMsg.Body = " Problem Occuread test mail";
                oMsg.SubjectEncoding = System.Text.Encoding.UTF8;
                oMsg.BodyEncoding = System.Text.Encoding.UTF8;
                oMsg.IsBodyHtml = false;
                oMsg.Priority = MailPriority.High;
 
                SmtpClient oSmtp = new SmtpClient("smtp.gmail.com", 587);
                oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                oSmtp.EnableSsl = true;
 
                NetworkCredential oCredential = new NetworkCredential("xxx@gmail.com", "123456aA");
                oSmtp.UseDefaultCredentials = false;
                oSmtp.Credentials = oCredential;
                oSmtp.Send(oMsg);


Thanks
--RA
 
Share this answer
 
v2
Use System.net namspace. create object for nerworkcredantial with ur gmail username and password.
 
Share this answer
 
Hi anoop,
use this code

C#
MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
           MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
           MailMessage newmsg = new MailMessage ( mailfrom, mailto );

           newmsg.Subject = "Subject of Email";
           newmsg.Body = "Body(message) of email";

           ////For File Attachment, more file can also be attached

           //Attachment att = new Attachment ( "G:\\code.txt" );
           //newmsg.Attachments.Add ( att );

           SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
           smtps.UseDefaultCredentials = false;
           smtps.Credentials = new NetworkCredential ( "mail@gmail.com", "pwd" );
           smtps.EnableSsl = true;
           smtps.Send ( newmsg );
 
Share this answer
 
v2
 
Share this answer
 
Hey Buddy,

I had created an article on the same:

http://www.c-sharpcorner.com/UploadFile/cd7c2e/send-bulk-mails-using-smtp-configuration-part-2/[^]

You can download the source code available in the Article
 
Share this answer
 
try this one once....

protected void btnSubmit_Click1(object sender, EventArgs e)
{
if (txtName.Text != "")
{
if (txtEmail.Text != "")
{
if (txtMessage.Text != "")
{
string result = "Message Sent Successfully..!!";
try
{


string senderID = ConfigurationManager.AppSettings["PFUserName"].ToString();// use sender's email id here..

try
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtEmail.Text);
// Recipient e-mail address.
Msg.To.Add("usermail");
Msg.Subject = "Feedback Mail";
Msg.Body = "Sender : " + txtEmail.Text + "\n" + "Name : " + txtName.Text + "\n" + "Subject : " + txtSubject.Text + "\n" + "Message:" + txtMessage.Text + "\n";
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("usermail", "Password");
smtp.EnableSsl = true;
smtp.Send(Msg);
//ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ASET", "<script type='text/javascript'>alert('Your Message Has Been Send ');</script>", false);
//CleaContents();
}
catch (Exception ex)
{
//result = "Error sending email.!!!";
result = ex.Message;
}
lbltxt.Text = result;
}
catch (Exception ex)
{
//result = "Error sending email.!!!";
result = ex.Message;
}
}
else
lblmsg.Text = "Please enter your Message";
}
else
lblEmail.Text = "Please enter your Mail Id";
}
else
lblname.Text = "Please enter your Name";


}
}
 
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