send email C# using smtp server with username password authentification
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);
Messag开发者_Go百科eBox.Show(b.Content + ":WORKED");
}
catch (Exception e4)
{
MessageBox.Show(b.Content + ": " +e4.Message);
MessageBox.Show(b.Content + ": " + e4.StackTrace);
}
I don't think you want to set
mailclient.UseDefaultCredentials = true;
Read more about this option here.
You should also test that you can actually send email through that smtp server.
Try connecting via telnet and authorizing. There are also plenty of services that will let you send a test message online (http://pingability.com/smtptest.jsp for example).
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.
you are attempting to login without sending the AUTH command first. this is why your web gui, which auto-inserts it's own AUTH commands works but your current client-application is not receiving a command from you to relay onto the server, but the server requires authentication.
maybe you need to Add mailclient.EnableSsl = true;
精彩评论