tags:

views:

11604

answers:

12

For some reason the accepted answer or any others don't work for me for this question.

can anyone else get this to work?

UPDATE: i have tried all the answers (accepted and otherwise) in the other question, but neither work.

I would just like to know if it works for anyone else, otherwise google have changed something (which has happened before).

When I try the piece of code that uses SmtpDeliveryMethod.Network, I quickly receive a SmtpException on Send(message). The message is "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at" <-- seriously, it ends there.

+1  A: 

The answer will probably be correct and your code not ;) (else why would somebody accept it)

So what is not working? error etc

PoweRoy
Well, have you considered the question being old? It's possible. Can you tell me definitely if that code works NOW? If you can I'll accept your answer
CVertex
It can be old and that gmail changes his settings. Yes that can be true but the lack of error messages I couldn't give any better answer. I saw the comment of freddy and this could be a solution!
PoweRoy
A: 

What about the non-accepted answer, have you tried that?

Benjol
+20  A: 

CVertex, make sure to review your code, and if that doesn't reveal anything post it. I was just enabling this on a test asp.net site I was working on, and it works.

Actually, at some point I had an issue on my code. Didn't spot it until I had a simpler version on a console program and saw it was working (no change on gmail side as you were worried about). The below code works just like the samples you referred to:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential("[email protected]", "mypwd"),
                EnableSsl = true
            };
            client.Send("[email protected]", "[email protected]", "test", "testbody");
            Console.WriteLine("Sent");
            Console.ReadLine();
        }
    }
}

I also got it working using a combination of web.config http://msdn.microsoft.com/en-us/library/w355a94k.aspx and code (because there is no matching EnableSsl in the config :().

eglasius
Worked brilliantly for me in a C# winforms application. Thanks, Freddy.
Andrew
I love it when code just works. +1
Sergio Tapia
Just remember that code like this is effectively transmitting your gmail credentials in plain text to the user...
Chris Marisic
there actually is a matching setting for enableSsl in the web.config, see answer below
Zidad
@Zidad that was added in 4.0.
eglasius
+1  A: 

Refer link below

send email using gmail in asp.net

+1  A: 

The problem is not one of technical ability to send through gmail. That works for most situations. If you can't get a machine to send, it is usually due to the machine not having been authenticated with a human at the controls at least once.

The problem that most users face is that Google decides to change the outbound limits all the time. You should always add defensive code to your solution. If you start seeing errors, step off your send speed and just stop sending for a while. If you keep trying to send Google will sometimes add extra time to your delay period before you can send again.

What I have done in my current system is to send with a 1.5 second delay between each message. Then if I get any errors, stop for 5 minutes and then start again. This usually works and will allow you to send up to the limits of the account (last I checked it was 2,000 for premier customer logins per day).

Jason Short
+1  A: 

Another thing that i've found is that you must change your password at least once. and try to use a Secure level Password (do not use the same user as password or 123456, etc)

A: 

I ran into this same error ( "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at" ) and found out that I was using the wrong password. I fixed the login credentials, and it sent correctly.

I know this is late, but maybe this will help someone else.

Albert Bori
A: 

I'm not sure which .net version is required for this because eglasius mentioned there is no matching enableSsl setting (I'm using .NET 4.0, but I suspect it to work in .NET 2.0+), but this configuration justed worked for me (and doesn't require you to any programmatic configuration):

<system.net>
  <mailSettings>
    <smtp from="[email protected]" deliveryMethod="Network">
      <network defaultCredentials="false" enableSsl="true" host="smtp.gmail.com" port="587" password="password" userName="[email protected]"/>
    </smtp>
  </mailSettings>
</system.net>

You might have to enable POP or IMAP on your gmail account first: https://mail.google.com/mail/?shva=1#settings/fwdandpop

I recommend trying it with a normal mail client first...

Zidad
that's new to 4.0, compare versions at -> http://msdn.microsoft.com/en-us/library/ms164242(v=VS.90).aspx
eglasius
Hi Eglasius... OK thanks for that! Strange they only have the programmatic approach in the pre-4.0. I guess we all forget things now and then :)
Zidad
A: 
Dim SMTPClientObj As New Net.Mail.SmtpClient
SMTPClientObj.UseDefaultCredentials = False
SMTPClientObj.Credentials = New System.Net.NetworkCredential("[email protected]", "mypwd")
SMTPClientObj.Host = "smtp.gmail.com"
SMTPClientObj.Port = 587
SMTPClientObj.EnableSsl = True
SMTPClientObj.Send("[email protected]","[email protected]","test","testbody")

If your get the error like "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at" as i get before this..make sure the SMTPClientObj.UseDefaultCredentials = False included and this line should before the SMTPClientObj.Credentials.

I did try to switch this 2 line opposite way and 5.5.1 Authentication Required error return.

Terry Chng
A: 

I had the same problem, but it turned out to be my virus protection was blocking outgoing "spam" email. Turning this off allowed me to use port 587 to send SMTP email via GMail

A: 

May be if u change the port number to 495 it works fine

client = new SmtpClient("smtp.gmail.com", 495)
SaeedAlg
A: 

You can also connect via port 465, but due to some limitations of the System.Net.Mail namespace you may have to alter your code. This is because the namespace does not offer the ability to make implicit SSL connections. This is discussed at http://blogs.msdn.com/b/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx, and I have supplied an example of how to use the CDO (Collaborative Data Object) in another discussion (GMail SMTP via C# .Net errors on all ports).

Bryan Allred