Click here to Skip to main content
11,929,232 members (65,176 online)
Rate this:
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).

SmtpClient smtpClient = new SmtpClient();
                MailAddress fromAddress = new MailAddress("");
                MailAddress toAddress = new MailAddress("");
                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 = "";
                smtpClient.Port = 587;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = new               System.Net.NetworkCredential("", "password");
                smtpClient.EnableSsl = true;

Error on sending is
The remote name could not be resolved: ''
Posted 26-Jan-12 20:17pm
Edited 26-Jan-12 20:29pm
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.
riteshsingh_jsr 27-Jan-12 1:30am
Yes Anuja, You are right...
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

can you please use below code
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
Anuja Pawar Indore 27-Jan-12 1:25am
Added pre tag
07navneet 27-Jan-12 1:28am
sorry! didnt work, same error thrown.
Rate this: bad
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");
                oMsg.To.Add(new MailAddress("", "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("", 587);
                oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                oSmtp.EnableSsl = true;
                NetworkCredential oCredential = new NetworkCredential("", "123456aA");
                oSmtp.UseDefaultCredentials = false;
                oSmtp.Credentials = oCredential;

07navneet 27-Jan-12 1:36am
same error again!! do i have to some thing in web.config also?
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

The remote name could not be resolved: ''

you are using
insted of this => use it's working

MailAddress mailfrom = new MailAddress ( "" );
            MailAddress mailto = new MailAddress ( "" );
            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 ( "", 587 );
            smtps.UseDefaultCredentials = false;
            smtps.Credentials = new NetworkCredential ( "", "pwd" );
            smtps.EnableSsl = true;
            smtps.Send ( newmsg );
Rajesh Anuhya 27-Jan-12 1:37am
pre tags added
07navneet 27-Jan-12 1:39am
print mistake!
Rate this: bad
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!
Rate this: bad
Please Sign up or sign in to vote.

Solution 6

hi 07navneet,

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

Bryian Tan
07navneet 28-Jan-12 2:01am
did you mean to type 'ping' in cmd prompt??
Bryian Tan 28-Jan-12 12:08pm
Rate this: bad
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[^]
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

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

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 27 Jan 2012
Copyright © CodeProject, 1999-2015
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