Click here to Skip to main content
15,910,878 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Hi all

The above error arising while using email sending code my code is
C#
string fromAddress = "mymail";
string fromPassword = "mypassword";
  
try
{
    var smtp = new System.Net.Mail.SmtpClient();
    {
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 20000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, MailSubject, Body);
}

I googled many times but didnt get proper solution. Port 587 is enbled and firewall blocking also not there.
Posted
v2
Comments
Street Racers 30-Oct-12 3:02am    
give full error details, including the stack information
satz_770 30-Oct-12 3:15am    
i think problem is with ur network connectivity.. chk ur network connection.. also post full error details..
amritha444 30-Oct-12 3:20am    
Thanks for the response
getting error as sending mail failed and getting inner exception as cannot connect to remote server. Which is working well in my system problem arising when i add this to server.we enabled that port and disabled firewall of server.What correct in network connection

First of all, make sure that the credentials are correct to connect to the gmail server.

Another thing is you have not assigned values to "MailSubject" or "Body", but called the function "smtp.Send()".

Please have a look at the useful answers at Sending email in .NET through Gmail[^], where I am able to find some differences.

Try to implement those answers.
Please let me know, if you still face problems, I will work out for you then.

Thanks...
 
Share this answer
 
Comments
amritha444 30-Oct-12 4:54am    
hi all
Thanks for the response.I got solution as
if you are using any antivirus software check it's log to see whether it is because of the antivirus. I faced same problem when McAffee was blocking my mails (there is a security policy - Prevent mass mailing worms from sending mails). Edit this policy and add your application to the exception list. In my case this sorted the problem. Please check if it works for you.
Well done...
hi all
Thanks for the response.I got solution as
if you are using any antivirus software check it's log to see whether it is because of the antivirus. I faced same problem when McAffee was blocking my mails (there is a security policy - Prevent mass mailing worms from sending mails). Edit this policy and add your application to the exception list. In my case this sorted the problem. Please check if it works for you.
 
Share this answer
 
hi all Thanks for the response.I got solution as if you are using any antivirus software check it's log to see whether it is because of the antivirus. I faced same problem when McAffee was blocking my mails (there is a security policy - Prevent mass mailing worms from sending mails). Edit this policy and add your application to the exception list. In my case this sorted the problem. Please check if it works for you.
 
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