-1

Possible Duplicate:
Sending email in .NET through Gmail

   using (var message = new MailMessage(fromAddress, toAddress)
        {
            Subject = subject,
            Body = body
        })
        {
            smtp.Send(message);
        }

I run the program and he brings me an error Failed to submit mail .. Here is the code what could be the problem?

Community
  • 1
  • 1
Israel
  • 1
  • 1

1 Answers1

3

Try the following:

using (var client = new SmtpClient("smtp.gmail.com", 587))
{
    client.EnableSsl = true;
    client.UseDefaultCredentials = false;
    client.Credentials = new NetworkCredential("username", "password");
    var message = new MailMessage(
        "sender@gmail.com", 
        "recipient@domain.com", 
        "some subject", 
        "mail body"
    );
    client.Send(message);
}

Also make sure that you are not behind a proxy and that the computer you are running this program on has access to smtp.gmail.com and that port 587 is not blocked by a firewall.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928