java - JavaMail - Unable to send mail using SSL -
i'm trying send mail enabling ssl using javamail office365 host. when i'm using host smtp.gmail.com
it's working fine not working smtp.office365.com
below approach:
public class sendmail { public static void main(string args[]){ string username = "abc@xyz.com"; string password = "abc123"; properties properties = new properties(); properties.put("mail.smtp.host", "smtp.office365.com"); properties.put("mail.smtp.socketfactory.port",995); properties.put("mail.smtp.socketfactory.class","javax.net.ssl.sslsocketfactory"); properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.ssl.enable", "true"); session session = null; if (authenticationrequired) { session = session.getinstance(properties, new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication(username,password); } }); }else{ session = session.getdefaultinstance(properties); } try{ mimemessage message = new mimemessage(session); message.setfrom(new internetaddress(username)); message.setsubject("test mail"); message.setcontent("test mail", "text/html"); message.setrecipients(message.recipienttype.to,internetaddress.parse(john@gmail.com)); transport transport = session.gettransport("smtp"); transport.connect(); transport.sendmessage(message,message.getallrecipients()); }catch(exception e){ e.printstack(); } } }
it throwing exception - could not connect smtp host: smtp.office365.com, port: 995 response: -1
. have tried port 993
not working. kindly me out. other approaches welcome
as said, works gmail did import gmail´s certificate keystore?
Comments
Post a Comment