.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

What is problem in following code

Posted By: Vikramraj     Posted Date: July 06, 2010    Points:2   Category :C#
I Have written following code to send Email to any Email id from gmail Acvcount

public void SENDEMAIL()
SmtpClient mClient = new SmtpClient();
mClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mClient.Host = "smtp.gmail.com";
mClient.Port = 587;

System.Net.NetworkCredential mCredential = new System.Net.Credential(my GMail ID, Password);
mClient.UseDefaultCredentials = false;
mClient.Credentials = mCredential;

MailMessage msg = new MailMessage(fromgmailID, ToEmailId);
msg.Subject = "Subject";
Msg.Subject.Encoding = System.Text.Encoding.UTF8;
msg.IsHtml = true;
msg.Body = "<html><head></head><body> Message </body></html>"

Page.Title = "Email Sent";
catch(Exception ex)
Page.Title = ex.ToString();


Author: Sunil Yadav       [Moderator]      
Posted Date: July 06, 2010     Points: 5   


Could you please tell me which Namespace you are using for SMTPClient from the Namespace listed below.


Author: Vikramraj             
Posted Date: July 07, 2010     Points: 5   


Author: Sunil Yadav       [Moderator]      
Posted Date: July 07, 2010     Points: 5   

If you are unable to send email then check weather firewall or antivirus is not blocking it.

Author: Vikramraj             
Posted Date: July 07, 2010     Points: 5   

Hi Sunil Thanks to give solutions. But actual problem is giving Error as follows
Failure Sending Mail System.Net. WebException Unable to connect Server. Plz Give me solution. Antivirus or Firewall is not abvailable on my PC. Still giving Same Error.

Author: Don             
Posted Date: January 11, 2011     Points: 5   

try this..
SmtpClient SmtpClient = new SmtpClient(smtp.gmail.com);

instead of this..

SmtpClient mClient = new SmtpClient();
mClient.Host = "smtp.gmail.com";

this may solve ur problm..
there is no mistake actually..

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend