4

When I run my app locally and click send on my contact form, I receive this error

Syntax error, command unrecognized. The server response was:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: Syntax error, command unrecognized. The server response was:

Line 65: await smtp.SendMailAsync(message);

I'm fairly new to creating contact forms. I'm using my gmail account to send details from user back to my mail

smtp.Credentials = credential;   
smtp.Host = "smtp.gmail.com"; 

smtp.Port = 465;   // SHOULD BE 587

smtp.EnableSsl = true;   
await smtp.SendMailAsync(message);   
return "sent";   

Thanks in advance!

[SmtpException: Syntax error, command unrecognized. The server response was: ]
   System.Net.Mail.ConnectAndHandshakeAsyncResult.End(IAsyncResult result) +1885147
   System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result) +31
   System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result) +49
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
Psyborg
  • 41
  • 3
  • Have you provided your Gmail credentials in the request? – Rory McCrossan Apr 13 '16 at 13:21
  • Hi Rory, Yes I did using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "", // replace with sender's email id Password = "" // replace with password }; – Psyborg Apr 13 '16 at 13:24
  • 4
    Please post the full *exception* including its call stack. You can get this with `Exception.ToString()`. The correct port for GMail though isn't 465, though, it's 587. The correct settings *are* mentioned in [Google's site](https://support.google.com/a/answer/176600?hl=en). Google for "GMail SMTP". Google no longer uses TLS, the same as all major sites. – Panagiotis Kanavos Apr 13 '16 at 13:30
  • Possible duplicate of [c# sendmail gmail smtp syntax error](http://stackoverflow.com/questions/36126731/c-sharp-sendmail-gmail-smtp-syntax-error) – Panagiotis Kanavos Apr 13 '16 at 13:31
  • 2
    Mr Kanavos! you were right! this syntax error was caused by using port 465! The correct port that worked was port 587 Thank you, I read up on that now! I appreciate it – Psyborg Apr 13 '16 at 13:40

0 Answers0