Click here to Skip to main content
15,882,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Whenever i am sending mail from gmail account its sending fine without any exception.
But when i tried it using some its failure.

MailMessage msg = new MailMessage();
            msg.From = new MailAddress(emailid);
            msg.Subject = "something";
            msg.Body = messageBody;
            SmtpClient sc = new SmtpClient("");     
            sc.Credentials = new NetworkCredential(emailid, password);
            sc.EnableSsl = true;

This code is not working .
I also tried by configuring web config.
      <smtp deliveryMethod="Network" from="">
        <network defaultCredentials="false" host="" enableSsl="true" userName="" password="*******" port="587"/>

But also its not working
Please suggest something
bbirajdar 18-Dec-12 2:00am    
contact your email host

Try the following:

private void SendEmail(string from, string to, string subject, string message)
        using (var email = new System.Net.Mail.MailMessage())
            email.From = new System.Net.Mail.MailAddress(from);

            email.Subject = subject;
            email.Body = message;

            var smtp = new System.Net.Mail.SmtpClient("IP ADDRESS HERE");

Hope it helps, cheers.
Share this answer
avikGhosh87 18-Dec-12 2:29am    
same error occuring.
Eyakem 18-Dec-12 2:45am    
try these:
1. Identfiy the host, smtp.Host = "";
2. Set the port number on your smtp client to 587, smtp.Port = 587;
3. gmail is secure so enable ssl, smtp.EnableSsl = true;

And last, please check if you have the login correct (case sensitive)
4. smtp.Credentials = new System.Net.NetworkCredential("", "your_password");
Usually most mail service providers only allow you to use their mail servers if you have an account with them.

So it begs the question whatever domain your using?....

Do you have an account or membership with (whatever the name of the domain is)

and are you using the mailserver settings they gave you?
Share this answer
avikGhosh87 18-Dec-12 2:28am    
Yes zaf i am using mailserver settings.
Zaf Khan 18-Dec-12 2:36am    
In that case, the best solution is as aspnet_regiis said in his/her comment....

aspnet_regiis -i - 33 mins ago
contact your email host

To ascertain whats up with their mail server.
Zaf Khan 18-Dec-12 2:41am    
Taking myself as an example...
When I make any changes to my mailing components,
there is no facility for me to test it from my development server.
My service provider states i MUST upload it and use the script on the server.
When i say my mail service provider what i mean is my HOSTING provider.

So i don't know if thats worth looking into for yourself?
Are you sending it from your HOSTING providers webspace in your account?
And using your mailing account credentials they gave you or you set up?
If you answer Yes then its best you get on the phone it may save you LOTS of time.

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