none
Problem with protocol

    Question

  • Hi,
    With these codes
                        MailMessage message = new MailMessage();
                        message.From = new MailAddress("Administrator@my-friend.co");
                        message.To.Add("peterchen@gmail.com");
                        message.Subject = "test message";
                        message.Body = "This is a test e-mail message sent by an application. ";
    
                        SmtpClient client = new SmtpClient("WIN-AIGPMD763AL.my-friend.co", 587);
                        client.DeliveryMethod = SmtpDeliveryMethod.Network;
                        client.Credentials = new System.Net.NetworkCredential("Administrator@my-friend.co", "?????");
                        client.EnableSsl = true;
                        client.Send(message);
                        ...
    


    I get these exception and Stacktrace. Any ideas?
    The server committed a protocol violation The server response was: UGFzc3dvcmQ6
       at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)


    Many Thanks & Best Regards, Hua Min

    Thursday, January 09, 2014 9:51 AM

Answers

All replies

  • The error message basically says that the status response from the HTTP application level did not return a 200 Done status.  You need to chack with your mail server documentation to see what port number and sercurity modes that it supports. 

    When you are sending the email you send it through your email server (not the To mail exchange) which is the From mail server and you must have the proper access rights.  You also have to make sure that no firewall or virus protection software is blocking the connection.  Because you are using SSL you may need to go through a relay server and the local mail server must recognize the relay server.


    jdweng

    Thursday, January 09, 2014 10:58 AM
  • If I use 25 port like
                        SmtpClient client = new SmtpClient("WIN-AIGPMD763AL.my-friend.co", 25);
                        ...
    


    then problem come back to be

    Mailbox unavailable. The server response was: 5.7.1 Unable to relay   
    at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)

    while I've created Inbound and Outbound exceptions on TCP Port 25 & 587, on both server and client machines. But is it true that 25, 587 are the only options we can use?

    Many Thanks & Best Regards, Hua Min

    Friday, January 10, 2014 2:31 AM
  • Yes/No.  Ports 25, 465, and 587 are the standard ports.  When using relay other non standard ports can be used as part of the relay.  The purpose of relay is so a firewall can block the standard ports numbers to prevent non authorized emails on a network, but still allow authorized email to get through. I don't know enough about the way email exchange implements the relay to give more information.  I'm just a theory guy and never had the opportunity to debug this type problem.

    jdweng

    Friday, January 10, 2014 4:47 AM
  • I do appreciate you and thanks! Any other help?

    Many Thanks & Best Regards, Hua Min


    Friday, January 10, 2014 4:51 AM
  • Any help to this?

    Many Thanks & Best Regards, Hua Min

    Monday, January 13, 2014 6:29 AM
  • There are too many reasons it may not work to start guessing and give you a solution.   This is the type of problems where you have to roll up your sleeves and start debugging. You are lucky that you have source code at the server to simplify the solving of the issue.  First get Outlook email working from the clients.  Then get yout VS application working.  Use a sniffer like wireshark or fiddler to help diagnose the problem.  Use the sniffer at client, server, and relay.   Also check any log files and the Control Panel : Administrative Tools : Event Viewer for error messages.  Here are some reasons for the problems

    1) Wrong configuration : Port number, relay options, security mode, credentials, encoding like GZip

    2) Data contents : Text, HTML, XML

    3) Virus Protection and Firewalls

    4) Group Policy Credentials

    Note : You have both windows credentials and Email credentials which may be different.


    jdweng

    Monday, January 13, 2014 7:34 AM
  • Thanks a lot.

    How to ensure Wireshark will be triggered, when I run the codes on the client machine?


    Many Thanks & Best Regards, Hua Min

    Monday, January 13, 2014 8:23 AM
  • I usually manually start the sniffer before starting the application.  I the computers aren't co-located then getting on the phone and calling somebody to start it for you will help.  When you have to debug applications that aren't co-located when use to call this "sneaker net" because you had to do a lot of walking.


    jdweng

    Monday, January 13, 2014 8:39 AM
  • Do I need Wireshark in both client and server machines?

    Many Thanks & Best Regards, Hua Min

    Monday, January 13, 2014 9:07 AM
  • It is Possible that you need both ends of the connection.  Usually I start out simple by analyzing one end of the connection and then see where that leads me.  Right now I think I would start at the server end.

    jdweng

    Monday, January 13, 2014 10:09 AM
  • Good day Joel,

    I'm running Wireshark now on both server and client machines. I've tried to do the same through the url on the client but after that, I see no specific errors of Email inside Event viewer within both the client and server machines, while I do still get the same error.

    The server committed a protocol violation The server response was: UGFzc3dvcmQ6
       at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)


    Many Thanks & Best Regards, Hua Min

    Tuesday, January 14, 2014 2:45 AM
  • See webpage below.  I think you have to use a networl password which means using the password on the PC.  Control panel has an email utility to setup an email account which can be used to setup an outlook account or a pop account.  You need to setup the proper account for you mail server with a password.  The change the credential statement from the one you are using to use the following

      SmtpClient client = new SmtpClient("WIN-AIGPMD763AL.my-friend.co", 587);
                client.UseDefaultCredentials = true;

    http://stackoverflow.com/questions/2380531/troubleshooting-the-server-committed-a-protocol-violation-when-sending-mail-wi


    jdweng

    Tuesday, January 14, 2014 8:37 AM
  • But I did have such line to pass the relevant login and password.
    ...
    client.Credentials = new System.Net.NetworkCredential("Administrator@my-friend.co", "?????");
    ...



    Many Thanks & Best Regards, Hua Min

    Tuesday, January 14, 2014 8:42 AM
  • The password has to be an encrypted password according to the website link I posted.  How are you encrypting the password?

    jdweng

    Tuesday, January 14, 2014 11:24 AM
  • Many many thanks. After I've used an encrypted password, the error then goes to this (even if I am using 25 port)
    Mailbox unavailable. The server response was: 5.7.1 Unable to relay
       at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)

    which is mentioned some days ago in this thread
    http://social.msdn.microsoft.com/Forums/en-US/d4aeb56a-cf01-4a0a-94e9-d2f22a512115/problem-with-mailbox?forum=csharpgeneral

    Many Thanks & Best Regards, Hua Min


    Wednesday, January 15, 2014 2:29 AM