Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SMTP
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 26-Jan-12 20:17pm
Edited 26-Jan-12 20:29pm
v4
Comments
Anuja Pawar Indore at 27-Jan-12 1:22am
   
Don't use word urgent
07navneet at 27-Jan-12 1:26am
   
mam, may i know why?
Anuja Pawar Indore at 27-Jan-12 1:28am
   
People are here not on job, they are here to help you as and when they find time.
07navneet at 27-Jan-12 1:37am
   
thanks! it will not happen again.
Anuja Pawar Indore at 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.
riteshsingh_jsr at 27-Jan-12 1:30am
   
Yes Anuja, You are right...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

can you please use below code
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
  Permalink  
v2
Comments
Anuja Pawar Indore at 27-Jan-12 1:25am
   
Added pre tag
07navneet at 27-Jan-12 1:28am
   
sorry! didnt work, same error thrown.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
07navneet at 27-Jan-12 1:36am
   
same error again!! do i have to some thing in web.config also?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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 );
  Permalink  
v2
Comments
Rajesh Anuhya at 27-Jan-12 1:37am
   
pre tags added
--RA
07navneet at 27-Jan-12 1:39am
   
print mistake!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

You can try following link,

Send mail using Google Apps[^]

Hope this may help you!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

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
  Permalink  
Comments
07navneet at 28-Jan-12 2:01am
   
did you mean to type 'ping smtp.gmail.com' in cmd prompt??
Bryian Tan at 28-Jan-12 12:08pm
   
yes.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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[^]
  Permalink  
v3
Comments
Anuja Pawar Indore at 27-Jan-12 1:33am
   
Added pre tag only when you are adding any piece of code.
07navneet at 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)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 27 Jan 2012
Copyright © CodeProject, 1999-2014
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