c# - Create a form for users to send email or gmail -


i created form includes send button , richtextbox , username , passsword , , textboxes.

this code in send button unfortunately program close when fill in textboxes , click on send button.

 private void btnsend_click(object sender, eventargs e)  {      mailmessage mail = new mailmessage(from.text, to.text, subject.text, body.text);       // smtoserver = smtp.company.com; ex: gmail . smtp.gmail.com | yahoo - smtp.yahoo.com       smtpclient client = new smtpclient(smtp.text);       client.port = 587;       client.credentials = new system.net.networkcredential(username.text,password.text);       client.enablessl = true;       client.send(mail);       messagebox.show("your mail has been sent!\n email",                       "success", messageboxbuttons.ok);   } 

update tried whatever said , watch youtube video compiler show me error in line 9 :

client.send(mail); 

and error :

an unhandled exception of type 'system.net.mail.smtpexception' occurred in system.dll

additional information: smtp server requires secure connection or client not authenticated. server response was: 5.5.1 authentication required.

you have follow tutorial : https://www.youtube.com/watch?v=4lzz0wzek14


Comments