java - Send email when JButton is clicked? -
someone please please thorough , me this, i've been @ forever now. i'm new programming , i've never set server or before. error trying run program. "java.net.connectexception: connection refused: connect
" , "javax.mail.messagingexception: not connect smtp host: localhost, port: 25;
"
here's code:
private void jbutton1actionperformed(java.awt.event.actionevent evt) { if (jbutton1.isenabled()); properties sessionproperties = system.getproperties(); string = "bleh@gmail.com"; string = "bleh@gmail.com"; string host = "localhost"; properties properties = system.getproperties(); properties.setproperty("mail.smtp.host", host); session session = session.getdefaultinstance(properties); try{ // create default mimemessage object. mimemessage message = new mimemessage(session); // set from: header field of header. message.setfrom(new internetaddress(from)); // set to: header field of header. message.addrecipient(message.recipienttype.to, new internetaddress(to)); // set subject: header field message.setsubject("infomation"); // set actual message message.settext("hello!"); // send message transport.send(message); }catch (messagingexception mex) { mex.printstacktrace();
it looks code came http://www.tutorialspoint.com/java/java_sending_email.htm if so, i'd direct sentence in tut
here assumed localhost connected internet , capable enough send email.
by capable, means have smtp server running on localhost; reason why got exception because transport
attempted use smtp server on localhost:25 send mail.
your options either run smtp server locally (a real pain) or use third-party smtp (gmail, amazon ses, etc.) service send mail.
Comments
Post a Comment