Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to send an email to my gmail id from my web application. For now I was sending from my same id(i.e. from/to on same ID).

Code:
SmtpClient smtpClient = new SmtpClient();
                MailAddress fromAddress = new MailAddress("navneet7988@gmail.com");
                MailAddress toAddress = new MailAddress("navneet7988@gmail.com");
                MailMessage message = new MailMessage(fromAddress, toAddress);
                message.Subject = "Feedback";
                message.IsBodyHtml = false;
                message.Body = "navneet";
                message.Priority = MailPriority.Normal;
                message.BodyEncoding = System.Text.Encoding.UTF8;

                smtpClient.Host = "smtp.gmail.com";
                smtpClient.Port = 587;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = new               System.Net.NetworkCredential("navneet7988@gmail.com", "password");
                smtpClient.EnableSsl = true;
                smtpClient.Send(message);


Error on sending is
The remote name could not be resolved: 'smpt.gmail.com'
Posted
Updated 26-Jan-12 19:29pm
v4
Comments
Anuja Pawar Indore 27-Jan-12 1:22am    
Don't use word urgent
07navneet 27-Jan-12 1:26am    
mam, may i know why?
Anuja Pawar Indore 27-Jan-12 1:28am    
People are here not on job, they are here to help you as and when they find time.
07navneet 27-Jan-12 1:37am    
thanks! it will not happen again.
Anuja Pawar Indore 27-Jan-12 1:40am    
Good you understand that people are not paid to help you, its there good will that they manage their time to help you. So you should be thankful to them,for taking time and helping you.

can you please use below code
C#
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
 
Share this answer
 
v2
Comments
Anuja Pawar Indore 27-Jan-12 1:25am    
Added pre tag
07navneet 27-Jan-12 1:28am    
sorry! didnt work, same error thrown.
use the below code to send the email
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
 
Comments
07navneet 27-Jan-12 1:36am    
same error again!! do i have to some thing in web.config also?
The remote name could not be resolved: 'smpt.gmail.com'

you are using smpt.gmail.com
insted of this smtp.gmail.com => use it's working

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
Comments
Rajesh Anuhya 27-Jan-12 1:37am    
pre tags added
--RA
07navneet 27-Jan-12 1:39am    
print mistake!
You can try following link,

Send mail using Google Apps[^]

Hope this may help you!
 
Share this answer
 
hi 07navneet,

Your original code is fine. Let try this. Ping the smtp.gmail.com, get its IP address and replace the smtp.gmail.com in your code with the IP address.


Thanks,
Bryian Tan
 
Share this answer
 
Comments
07navneet 28-Jan-12 2:01am    
did you mean to type 'ping smtp.gmail.com' in cmd prompt??
Bryian Tan 28-Jan-12 12:08pm    
yes.
You also need to enable POP by going to settings > Forwarding and POP in your gmail account

also u can try it
http://www.shabdar.org/asp-net/111-send-email-from-your-gmail-account-using-aspnet-and-c.html[^]
 
Share this answer
 
v3
Comments
Anuja Pawar Indore 27-Jan-12 1:33am    
Added pre tag only when you are adding any piece of code.
07navneet 27-Jan-12 2:15am    
no!

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