java - using javax.mail to send message -


i send email using javax.mail example@uni.ac.uk receiver@uni.ac.uk. have tried below code gives error put below. welcome.

    properties prop = new properties();     session sess = session.getdefaultinstance(prop,null);      message msg = new mimemessage(sess);     msg.setfrom(new internetaddress("example@uni.ac.uk", "sender"));              msg.addrecipient(message.recipienttype.to,                       new internetaddress("receiver@uni.ac.uk", "receiver"));             msg.setsubject("your example.com account has been activated");             msg.settext("testing messgage");            transport.send(msg);   } 

error generated

exception in thread "main" javax.mail.messagingexception: not connect to
smtp host: localhost, port: 25; nested exception is: java.net.socketexception: permission denied: connect @ com.sun.mail.smtp.smtptransport.openserver(smtptransport.java:1962) @ com.sun.mail.smtp.smtptransport.protocolconnect(smtptransport.java:654) @ javax.mail.service.connect(service.java:295) @ javax.mail.service.connect(service.java:176) @ javax.mail.service.connect(service.java:125) @ javax.mail.transport.send0(transport.java:194) @ javax.mail.transport.send(transport.java:124) @ mail.sendmail.main(sendmail.java:41) caused by: java.net.socketexception: permission denied: connect @ java.net.plainsocketimpl.socketconnect(native method) @ java.net.plainsocketimpl.doconnect(unknown source) @ java.net.plainsocketimpl.connecttoaddress(unknown source) @ java.net.plainsocketimpl.connect(unknown source) @ java.net.sockssocketimpl.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.connect(unknown source) @ com.sun.mail.util.socketfetcher.createsocket(socketfetcher.java:321) @ com.sun.mail.util.socketfetcher.getsocket(socketfetcher.java:237) @ com.sun.mail.smtp.smtptransport.openserver(smtptransport.java:1928) ... 7 more

here example properties send email using gmail:

private properties createconfiguration() {     return new properties() {{         put("mail.smtp.auth", "true");         put("mail.smtp.host", "smtp.gmail.com");         put("mail.smtp.port", "587");         put("mail.smtp.starttls.enable", "true");     }}; } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -