Click here to Skip to main content
15,119,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am just trying to generate an email using C#, however, I think I am using the wrong SMTP server, as Gmail times out for some reason. Is there some security configuration required by Google Mail on the From address, or some authentication mechanism that I need to go through, since this is obviously a 'spam' email example?

What would you suggest?

               MailMessage m = new MailMessage();
               m.Subject = "test";
               m.From = new MailAddress("");
               SmtpClient smtp = new SmtpClient("");
           catch (Exception ex) { Console.WriteLine(ex.Source); }
Sergey Alexandrovich Kryukov 19-Nov-13 12:22pm
It would make a good answer. Why not posting it as a formal answer?

Having a mail-server address doesn't mean you can use it.

Usually, you need to be authenticated in some manner, perhaps simply making the query from it's domain. Since you're not making the request from the appropriate location (some part of google) you are rejected by the server.

As an experiment, switch the mail server to the server for they system where your client is authenticated. This may work.

I recently developed a code as part of a contact page in a website which needed to send email here is the code.

var sender = contact.Email;

           var email = new MailMessage();
           email.To.Add(new MailAddress(""));
           email.From = new MailAddress("");
           email.Subject = form["Tipo de contacto"] + " de " + sender;
           email.Body = contact.Message;
           email.IsBodyHtml = true;
           email.Priority = MailPriority.Normal;

           var smtp = new SmtpClient
                              Host = "",
                              Port = 25,
                              EnableSsl = false,
                              UseDefaultCredentials = false,
                              Credentials = new NetworkCredential("", "lade$23")


               var verificationEmail = new MailMessage();
               verificationEmail.To.Add(new MailAddress(sender));
               verificationEmail.From = new MailAddress("");
               verificationEmail.Subject = "Su " + form["Tipo de contacto"] + " será atendida " + sender;
               verificationEmail.Body = "Atenderemos su " + form["Tipo de contacto"] + " a la mayor brevedad posible";
               verificationEmail.IsBodyHtml = true;
               verificationEmail.Priority = MailPriority.Normal;


               ViewData["Message"] = "Su mensaje ha sido enviado satisfactoriamente";
           catch (Exception)

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