Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all!!

i am trying to send error log email from my site but the following error pops up everytime..

Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 74.125.236.86 (74.125.236.86:587), connect error 10060


MailClient.Credentials = new NetworkCredential(MonalConfiguration.MailUsername, MonalConfiguration.MailPassword);

MailMessage mailmessage = new MailMessage(from, to, subject, body);

MailClient.Send(mailmessage);




Here are the settings in my web.cofig

XML
<appSettings>
    <add key="MailServer" value="mail.google.com"/>
    <add key="MailUsername" value="UserName@gmail.com"/>
    <add key="MailPassword" value="Password"/>
    <add key="MailFrom" value="UserName@gmail.com"/>
    <add key="EnableErrorLogEmail" value="true"/>
    <add key="ErrorLogEmail" value="ujjwal.uniyal111@gmail.com"/>
  </appSettings>




this is my configuration file

C#
public static  class MonalConfiguration
{
    private static string dbConnectionString;
    private static string dbProviderName;

    static  MonalConfiguration()
    {
        dbConnectionString = ConfigurationManager.ConnectionStrings["Constr"].ConnectionString;
        dbProviderName = ConfigurationManager.ConnectionStrings["Constr"].ProviderName;
    }

    public static string DbConnectionString
    {
        get { return dbConnectionString; }

    }
    public static string DbProviderName
    {
        get { return dbProviderName; }
    }

    public static string MailServer
    {
        get {  return ConfigurationManager.AppSettings["MailServer"];}
    }

    public static string MailUsername
    {
        get { return ConfigurationManager.AppSettings["MailUsername"] ;}
    }

    public static string MailFrom
    {
        get { return ConfigurationManager.AppSettings["MailFrom"] ;}
    }

    public static string MailPassword
    {
        get { return ConfigurationManager.AppSettings["MailPassword"];}
    }

    public static bool EnableErrorLogEmail
    {
        get { return bool.Parse (ConfigurationManager.AppSettings["EnableErrorLogEmail"]); }
    }
    public static string ErrorLogEmail
    {
        get { return ConfigurationManager.AppSettings["ErrorLogEmail"]; }
    }
}
Posted
Updated 3-Apr-12 21:58pm
v3

you miss the stmp port number and you should enablessl. Read it here[^]
 
Share this answer
 
I changed the value of key ="MailServer" from value="mail.google.com" to

value ="smtp.gmail.com"

and it worked fine...
 
Share this answer
 
try this

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 ( "urmail@gmail.com", "urpwd" );
smtps.EnableSsl = true;
smtps.Send ( newmsg );


System.Net.Mail Namespace[^]
 
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