send email C# using smtp server with username password authentification

Posted by KK on Stack Overflow See other posts from Stack Overflow or by KK
Published on 2010-04-28T17:29:49Z Indexed on 2010/04/28 21:27 UTC
Read the original article Hit count: 348

Filed under:
|
|
|

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

This is not working for me. This a remote smtp service ... and i double checked that email web access works fine .. i can login using the gui, recieve and send emails.

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

{System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 No AUTH command has been given.

Can anybody advise ... and also they dont have EWS exposed ie.e exchange web service ./.. this is the way to go ..

port is 25 and 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);
}

© Stack Overflow or respective owner

Related posts about sendmail

Related posts about c#