java - SMTP not getting connected -
here java code send email, whenever run code shows javax.mail.messagingexception: not connect smtp host: ipaddress, port: 25; tried changing port number, still same error.. can me.. (i have included mail.jar , activation.jar project)
public static void main(string arfs[]) throws unknownhostexception { inetaddress address = inetaddress.getlocalhost(); string to="gggg@gmail.com"; string from="vvvvv@gmail.com"; string host=address.gethostaddress(); properties properties = system.getproperties(); properties.setproperty("mail.smtp.host",host); properties.setproperty("mail.smtp.port", "25"); session session = session.getdefaultinstance(properties); try{ mimemessage message = new mimemessage(session); message.setfrom(new internetaddress("vvvv@gmail.com")); message.addrecipient(message.recipienttype.to,new internetaddress("ggggg@gmail.com")); message.setsubject("test email"); message.settext("hello"); transport.send(message); system.out.println("message sent successfully...."); } catch(messagingexception mex) { mex.printstacktrace(); } }
check whether system has smtp access?
Comments
Post a Comment