Send email c # using smtp server with username authentication

I have a piece of code that sends email .. heres the code

It doesn't work for me. This is an smtp remote service ... and I double checked that email access is working fine. I can login with gui, receive and send emails.

But when I try to do it with code .. it fails with the message ...

{System.Net.Mail.SmtpException: The SMTP server requires a secure connection, or the client was not authenticated. Server response: 5.7.0 AUTH command not specified.

Can anyone please advise ... and also they don't have EWS exposed i.e. web service exchange. / .. is the way to go.

port is 25 and has no SSL or TLS

Button b = sender as Button;
try
{
    MailMessage msg = new MailMessage(senderEmail, recieverEmail, "afdasfas", "safasfa");
    //MailMessage msg = new MailMessage(senderEmail, recieverEmail, subject, subject);
    System.Net.Mail.SmtpClient mailclient = new System.Net.Mail.SmtpClient(EmailSmtpServer, outgoingPort);
    System.Net.NetworkCredential auth = new System.Net.NetworkCredential(senderEmail, senderPassword);
    mailclient.Host = EmailSmtpServer;
    mailclient.UseDefaultCredentials = false;
    mailclient.Credentials = auth;
    mailclient.Send(msg);
    MessageBox.Show(b.Content + ":WORKED");
}
catch (Exception e4)
{
    MessageBox.Show(b.Content + ": " +e4.Message);
    MessageBox.Show(b.Content + ": " + e4.StackTrace);
}

      

+2


a source to share


3 answers


I don't think you want to install

mailclient.UseDefaultCredentials = true;

      

Read more about this option here .




You should also check that you can actually send email through this SMTP server.

Try to telnet and authorize. There are also many services that will allow you to send a test message online ( http://pingability.com/smtptest.jsp , for example).

+4


a source


System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client is not authenticated. Server response: 5.7.0 AUTH command not specified.



you are trying to login without sending the AUTH command . so your web gui, which automatically inserts its own AUTH commands , works, but your current client application does not receive a command from you to relay to the server, but the server requires authentication .

+1


a source


maybe you need to add mailclient.EnableSsl = true;

0


a source







All Articles