send email C# using smtp server with username password authentification -


i have piece of code sends email.. heres code

this not working me. remote smtp service ... , double checked email web access works fine .. can login using gui, recieve , send emails.

but when try through code .. fails message ...

{system.net.mail.smtpexception: smtp server requires secure connection or client not authenticated. server response was: 5.7.0 no auth command has been given.

can advise ... , dont have ews exposed ie.e exchange web service ./.. way go ..

port 25 , no ssl or tls

button b = sender 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); } 
share|improve question
    
can put code in code block? makes easier read. – jaltiere apr 28 '10 @ 17:33
up vote 4 down vote accepted

i don't think want set

mailclient.usedefaultcredentials = true; 

read more option here.


you should test can send email through smtp server.

try connecting via telnet , authorizing. there plenty of services let send test message online (http://pingability.com/smtptest.jsp example).

share|improve answer
    
no .. sorry thas typo .. trying options .. edit post ... exception when trying run code {system.net.mail.smtpexception: smtp server requires secure connection or client not authenticated. server response was: 5.7.0 no auth command has been given. @ system.net.mail.mailcommand.checkresponse(smtpstatuscode statuscode, string response) – pskk apr 28 '10 @ 18:26
    
@kk, see edit. – joel apr 28 '10 @ 21:22
    
i can telnet remote smtp service ... when use auth login , provide username , password in base64 format , can login ... guess problem in c# code ... , sendmail not send "auth login" command or not send username/password in base64 ... think can point me blog/site has corrected ... tried bunch of them , didnt work me ... thank you. – pskk apr 29 '10 @ 12:27
    
@kk, code have looks good. passing username , password networkcredential constructor in plain text? – joel apr 29 '10 @ 13:11
    
also, check firewall. – joel apr 29 '10 @ 13:12

system.net.mail.smtpexception: smtp server requires secure connection or client not authenticated. server response was: 5.7.0 no auth command has been given.

you attempting login without sending auth command first. why web gui, auto-inserts it's own auth commands works current client-application not receiving command relay onto server, server requires authentication.

share|improve answer

maybe need add mailclient.enablessl = true;

share|improve answer
    
no .. sorry thas typo .. trying options .. edit post ... exception when trying run code {system.net.mail.smtpexception: smtp server requires secure connection or client not authenticated. server response was: 5.7.0 no auth command has been given. @ system.net.mail.mailcommand.checkresponse(smtpstatuscode statuscode, string response) – pskk apr 28 '10 @ 18:27
    
the remote smtp service not need smtp enabled – pskk apr 28 '10 @ 18:29
    
i can telnet remote smtp service ... when use auth login , provide username , password in base64 format , can login ... guess problem in c# code ... , sendmail not send "auth login" command or not send username/password in base64 ... think can point me blog/site has corrected ... tried bunch of them , didnt work me ... thank you. – pskk apr 29 '10 @ 12:27

your answer

 
discard

posting answer, agree privacy policy , terms of service.

not answer you're looking for? browse other questions tagged or ask own question.

Comments