How to send email in java GWT -
i using code in java gwt application
public string greetserver(string input) throws exception { try{ properties props = new properties(); props.setproperty("mail.transport.protocol", "smtp"); props.setproperty("mail.smtp.port", "25"); props.setproperty("mail.host", "smtp.random.com"); props.setproperty("mail.user", "foo@bar.com"); props.setproperty("mail.password", "000000000"); session mailsession = session.getdefaultinstance(props, null); transport transport = mailsession.gettransport(); mimemessage message = new mimemessage(mailsession); message.setsubject("hello"); message.setcontent("helloo sss", "text/plain"); message.addrecipient(message.recipienttype.to, new internetaddress("junaidp@gmail.com")); transport.connect(); transport.sendmessage(message, message.getrecipients(message.recipienttype.to)); transport.close(); } catch(nosuchproviderexception e){ throw new exception(e); } return input; }
error: javax.mail.messagingexception: not connect smtp host: smtp.random.com, port: 25; nested exception is: java.net.connectexception: connection refused: connect
if use
props.setproperty("mail.host", "smtp.live.com"); , use hotmail account , gives error javax.mail.messagingexception: can't determine local email address
any idea solution
thanks
here's gmail settings work me:
//these fed properties object below: mail.smtp.starttls.enable = true mail.transport.protocol = smtp mail.smtp.auth = true
and java:
properties properties = ... javax.mail.session session = javax.mail.session.getinstance(properties, null); transport transport = session.gettransport("smtp"); transport.connect("smtp.gmail.com", username, password);
Comments
Post a Comment