java - runtime error. Problem with SMTP server -


hi running following program getting run time error.i have pasted below.

import java.util.properties;  import javax.mail.message; import javax.mail.messagingexception; import javax.mail.passwordauthentication; import javax.mail.session; import javax.mail.transport; import javax.mail.internet.internetaddress; import javax.mail.internet.mimemessage; import javax.mail.internet.mimemessage.recipienttype;  public class mailwithpasswordauthentication {  public static void main(string[] args) throws messagingexception {   new mailwithpasswordauthentication().run();  }   private void run() throws messagingexception {   message message = new mimemessage(getsession());    message.addrecipient(recipienttype.to, new internetaddress("abc@yahoo.co.in"));   message.addfrom(new internetaddress[] { new internetaddress("xyz@gmail.com") });    message.setsubject("the subject");   message.setcontent("the body", "text/plain");    transport.send(message);  }   private session getsession() {   authenticator authenticator = new authenticator();    properties properties = new properties();   properties.setproperty("mail.smtp.submitter", authenticator.getpasswordauthentication().getusername());   properties.setproperty("mail.smtp.auth", "true");    properties.setproperty("mail.smtp.host", "smtp.gmail.com");   properties.setproperty("mail.smtp.port", "25");    return session.getinstance(properties, authenticator);  }   private class authenticator extends javax.mail.authenticator {   private passwordauthentication authentication;    public authenticator() {    string username = "xyz@gmail.com";    string password = "xyz";    authentication = new passwordauthentication(username, password);   }    protected passwordauthentication getpasswordauthentication() {    return authentication;   }  } } 

runtime error

exception in thread "main" com.sun.mail.smtp.smtpsendfailedexception: 530 5.7.0 must issue starttls command first. u8sm278510wbc.23   @ com.sun.mail.smtp.smtptransport.issuesendcommand(smtptransport.java:1829)  @ com.sun.mail.smtp.smtptransport.mailfrom(smtptransport.java:1368)  @ com.sun.mail.smtp.smtptransport.sendmessage(smtptransport.java:886)  @ javax.mail.transport.send0(transport.java:191)  @ javax.mail.transport.send(transport.java:120)  @ mailwithpasswordauthentication.run(mailwithpasswordauthentication.java:26)  @ mailwithpasswordauthentication.main(mailwithpasswordauthentication.java:14) 

try add properties.setproperty("mail.smtp.starttls.enable", "true");


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -