java - Email is sending but not receiving when use no authentication -
i sending email using
public void sendemail(string fromemailaddr, string toemailaddr,string subject, string emailbody) { string host = "xxx"; final string user = "user"; final string password = "password"; // system properties properties properties = new properties(); // setup mail server properties.put("mail.smtp.host", host); properties.put("mail.smtp.port", "25"); // default session object. session session = session.getdefaultinstance(properties, null); try{ // create default mimemessage object. mimemessage message = new mimemessage(session); // set from: header field of header. message.setfrom(new internetaddress(fromemailaddr)); // set to: header field of header. message.addrecipient(message.recipienttype.to, new internetaddress(toemailaddr)); // set subject: header field message.setsubject(subject); // set actual message message.settext(emailbody); // send message transport.send(message); system.out.println("sent message successfully...."); }catch (messagingexception mex) { mex.printstacktrace(); } }
when try send email using above code comes message sent message successfully....
got no email. on other hand if use authentication got email
properties.put("mail.smtp.host", host); properties.put("mail.smtp.auth", "true"); session session = session.getdefaultinstance(properties, new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication(user,password); } });
why ? necessary provide username , password host ? can send email specifying host, no username , password provided ?
thanks
i guess port number might issue.
try changing properties.put("mail.smtp.port", "25");
to properties.put("mail.smtp.port", "587");
.
further can refer this.
Comments
Post a Comment