Sending inputs to email? WinForm C# -
i'm working on simple winform project have textbox user inputs name. when clicks on button want able send input email address or that.
would possible? if how do it?
the following code serves send email custom smtp client:
using system; using system.net.mail; class program { static void main(string[] args) { try { mailmessage mail = new mailmessage(); smtpclient smtpserver = new smtpclient("smtp.customsmtp.com"); mail.from = new mailaddress("fromemail@fromemail.com"); mail.to.add("toemail@toemail.com"); mail.subject = "your subject"; mail.body = "your textbox here!"; smtpserver.send(mail); } catch (exception ex) { console.writeline("seems problem!"); } console.writeline("email sent successfully!"); console.readline(); } }
the sample below send e-mail gmail account using gmail username , password:
using system; using system.net; using system.net.mail; namespace gmailsample { class simplesmtpsend { static void main(string[] args) { smtpclient client = new smtpclient("smtp.gmail.com", 587); client.enablessl = true; mailaddress = new mailaddress("yourgmailusername@gmail.com", "[ full name here]"); mailaddress = new mailaddress("your recipient e-mail address", "your recepient name"); mailmessage message = new mailmessage(from, to); message.body = "this test e-mail message sent using gmail relay server "; message.subject = "gmail test email ssl , credentials"; networkcredential mycreds = new networkcredential("yourgmailusername@gmail.com", "yourpassword", ""); client.credentials = mycreds; try { client.send(message); } catch (exception ex) { console.writeline("exception is:" + ex.tostring()); } console.writeline("goodbye."); } } }
hope helps!
Comments
Post a Comment